Blog › What happens when you press Next in a random video chat

What happens when you press Next in a random video chat

By Gowrishankar Rangasamy · · Updated

Pressing Next looks like one action. Underneath it is a short chain of messages between your browser, the matching server and the other person's browser. I'll walk through it as it works on Chatzyo, because a few details surprise people.

Your side: one message

When you press Next, your browser sends the matching server a single message, skip-video. It closes your connection to the other person, clears the chat panel, and shows "Looking for someone". Nothing else is needed from you.

The server's side

When the server receives skip-video, it does four things:

  1. It takes you out of the room you shared with the other person.
  2. It tells the other person's browser that their partner is gone, with a message called peer-skipped.
  3. It makes sure you aren't on the waiting list twice.
  4. About a tenth of a second later, it tries to match you again.

The server also ignores a Start or Next that arrives less than 300 milliseconds after your previous one. That guard stops a double-click from skipping two people in a row, but it also means the second click vanishes silently, with no error. Because of that, Chatzyo.live slows its own Next button to one press every half second so a click is never swallowed without anyone noticing.

The other person's side

The person you left receives peer-skipped. Their browser closes the connection and shows that it's looking for someone new.

Two things are worth knowing here.

They aren't told why you left. Their page shows the same text whether you pressed Next, closed the tab, lost your Wi-Fi or switched off your phone. Underneath, the server uses one signal for Next and for a dropped connection, and a slightly different one when someone presses Stop or closes the tab politely. Neither carries a reason or a name. If you've ever wondered whether a person who disappeared did so on purpose, there is nothing in the connection that can answer that.

They aren't put back in line automatically. After the server tells them you've gone, it is up to their browser to ask for a new match. Chatzyo.live's page waits 400 milliseconds and then asks again.

Why you're matched again so quickly

You are put back on the waiting list by the server within about a tenth of a second. The person you left has to wait for their browser to ask again, which takes a few times longer. So the person who pressed Next usually gets back in line first.

Can you meet the same person again?

Matching doesn't try to avoid people you've just left: it works from the waiting list, in order of arrival. The server does hold on to who you were paired with for a couple of minutes, but only so that a report about that person can be checked. The one exception is someone you report or block: you won't be matched with them again for as long as you stay connected (a reload or a dropped connection ends that).

I traced through what that means when almost nobody is online. You press Next, and a tenth of a second later the server puts you on an empty waiting list. The person you left asks for a new match a fraction of a second after that, finds you waiting, and is paired with you again. It's rare when many people are online, because there is usually someone else already waiting. At a quiet hour with few people, you should expect to bump into the same person once or twice.

This is a known trade-off of a simple design. Avoiding everyone you've just left is possible, but it costs memory and needs rules for how long to remember. A feature like that has to be built into the server, and it's one of the things I'd add in a stricter version.

What Next doesn't do

Where to go from here

If you want the larger picture of how a call is set up, read how Chatzyo works. For ways to protect yourself when a conversation goes wrong, see safety.