How strangerly Is Built: The Tech Behind Random Video Chat
Strangerly Team · · 11 min read
strangerly connects two strangers for a text, voice or video chat in a few seconds. That sounds simple. Underneath, it involves a matchmaking queue, peer-to-peer video that has to work on Indian mobile networks, AI safety models that run on the user's own device, and a website and an Android app that have to behave exactly the same way.
This post explains what we use, how we put it together, and what we learned along the way.
The big picture
| Part | What we use |
|---|---|
| Website | Remix 2, React 18, Vite |
| Android app | Flutter, Riverpod, go_router |
| Realtime backend | Firebase Realtime Database, anonymous auth |
| Records (reports, purchases) | Cloud Firestore |
| Video and voice | WebRTC, with Cloudflare Realtime TURN relays |
| On-device AI | TensorFlow.js in the browser, TensorFlow Lite in the app |
| Hosting | Vercel and Cloudflare Workers, from one build |
| Storage | Cloudflare R2 |
There are two clients and one backend. That decision shapes almost everything else.
Two apps, one shared room
A web user and an app user can be matched together. To make that work, both clients read and write the same paths and the same data shapes in Firebase Realtime Database. A chat room is one small tree: who is in it, the room details, the chat messages and the state of any game being played.
A shared schema has a cost: any change has to ship in both clients at the same time, or cross-platform chats break. We handle this in three ways:
- Pure rule modules. All the decision logic (how candidates are ranked, when a filter relaxes, how a game round is scored, what counts as a bad display name) lives in small files with no network or UI code. The website has a TypeScript version and the app has a Dart version.
- Shared test vectors. Each pair of files is tested against the same inputs and expected outputs. If someone changes a weight on one side and not the other, a test fails.
- One side is in charge. In each room, one participant is side
aand the other is sideb. Anything that must happen exactly once, such as scoring a game round or posting a system message, is done by sidea. That avoids double scores and repeated messages without needing a server in the middle.
Matchmaking without a matchmaking server
When you tap Start, your device writes a small entry into a queue for your mode (text, voice or video). The entry holds your preferences: interests, languages, region, an approximate position if you chose "Nearby", and whether you have Fast Skip.
The clients then match among themselves.
- Only one side claims. Between any two waiting people, only the one with the lower user id starts the match. That means two phones never try to grab each other at the same time.
- Filters are checked from both sides. If you only want people who share your interests, the person claiming you has to respect that too.
- Candidates are ranked, not just filtered. Shared interests add points, being nearby adds points, Fast Skip adds priority, and recent reports from other users subtract points. The best-scoring candidate is claimed first.
- The claim is a transaction. Both queue entries are removed atomically. If someone else got there first, the transaction fails cleanly and the search continues.
Preferences that relax
A small queue can't satisfy every filter. If your filters are too narrow, you could wait forever. So interests, region and language are soft for a short window, about 9 seconds, and distance for about 20 seconds. After that they turn into ranking hints, and the app tells you it widened the search instead of quietly ignoring your choice.
Keeping location private
"Nearby" matching needs some idea of where you are. We never store your actual coordinates. Your device rounds your position to a fixed grid of about 1 km before anything is written. We chose a fixed grid over random noise on purpose: random noise can be averaged out if someone samples your location many times, while a fixed grid always gives the same rounded answer. The other person sees only a rough distance such as "~5 km".
Region and country come from your device's language and timezone settings, not from your IP address, and don't need any permission.
Watching the database bill
Firebase Realtime Database charges for the data your users download. That pushes the design in specific directions:
- A searcher only listens to the part of the queue it is allowed to claim, starting from its own id, rather than the whole queue.
- Lookups such as bans and reputation are done for the top few candidates only, not for everyone in the queue.
- No client ever reads a list that grows with the number of users. Counts such as "people nearby" are prepared once a minute by a scheduled job and read as a single small value.
What we're testing now: with client-side matching, every searcher downloads part of the queue, so the cost grows quickly as more people join. We're trialling a server matchmaker on a Cloudflare Durable Object: one listener on the queue that pairs people every second using the same rule modules the clients use. It is switched off by default, and it uses the same steps a phone would, so older app versions are matched as normal. If the server stops responding, clients go back to matching among themselves after 15 seconds.
Video that works on Indian mobile networks
Calls use WebRTC, so audio and video go directly between the two devices. The Realtime Database is used only to exchange the setup messages ("signaling") that let two devices find each other.
TURN relays
Many Indian mobile carriers put users behind carrier-grade NAT, which blocks most direct connections. Without a relay, those calls simply fail with no error message. We added Cloudflare Realtime TURN: a small API route checks the user's Firebase sign-in, creates short-lived relay credentials, and returns them. Both clients cache the credentials and fall back to a static configuration if the route is slow or unavailable, so calling never depends on it.
The relay only forwards encrypted packets. It cannot see or hear the call.
Fewer signaling messages
When we profiled our database usage, about 80% of it was WebRTC signaling. By default, each network path a device discovers (an "ICE candidate") is sent as a separate message. Now each side waits until it has finished collecting candidates, or for one second, whichever comes first, and sends them all inside a single offer or answer. Only late candidates are sent separately. We also cut the relay addresses we send from five to two (one UDP, one TLS on port 443). Older clients still accept the new format, so nothing broke during the switch.
Tuned for phones
Video is captured at 640×480, 24 frames per second, and capped at 600 kbps, with the encoder told to keep the frame rate smooth rather than the picture sharp. For a face-to-face chat on a mobile connection, smooth motion matters more than detail.
AI that runs on your device
We use AI for safety, but the models run on your phone or in your browser, not on our servers. Only the result leaves the device.
Nudity Shield
A MobileNetV2 image classifier (the open-source NSFWJS model, MIT licence) checks the other person's video a few times a second. If it is confident across consecutive checks, their video is blurred and you get a one-tap "Report & next". It never reports anyone by itself.
Some details from building it:
- Two crops per frame. Each check looks at the whole frame and a centre square, and takes the higher score. People are often small in the frame, and the centre crop catches that.
- A Web Worker on the website. Our face model already loads an older TensorFlow.js version on the page, and two versions on one page share a global engine and conflict. Running the nudity model in a Web Worker gives it its own TensorFlow.js 4 environment.
- The same model in the app. The app uses a TensorFlow Lite conversion of the same model, checked against the browser output, so a frame gets the same verdict on both.
- A second opinion in the app. When the first model finds a frame suspicious, the app runs a small vision transformer (Marqo's nsfw-image-detection, Apache-2.0) on that frame. Both models have to agree before the strongest actions are taken. That cuts false alarms, such as a raised arm being flagged.
- Self guard. The same model checks your own camera. If it sees nudity, your video is paused for the other person before they see it.
We adjusted the thresholds using real reports. Our first setting let too much through, and a stricter one paused about one in fifteen video chats for people who had just raised their arms. The current setting uses a different threshold for blurring someone else's video than for pausing your own.
Age and gender estimation
The website uses face-api.js's age and gender model. For the app, we rebuilt that same model as a TensorFlow Lite file, so the app and the website read a face the same way: gender within ±0.01 and age within half a year of the browser's result. It only commits to a reading when it is confident over several frames, and your own choice always overrides it. In the app it also acts as an age check: if the camera consistently sees a child, chat is closed on that phone for a day.
Weaker phones
Running a neural network several times a second is heavy on budget phones. The app's scan loop pauses for twice as long as the last scan took, up to two seconds, so a slow phone scans less often instead of freezing the call.
Translation
On desktop Chrome and Edge, the website can translate the other person's messages using the browser's built-in Translator API, entirely on device. We deliberately didn't add a cloud fallback: sending chat text to a translation server would undo the privacy that makes the feature worth having. Where the API isn't available, the button doesn't appear.
One codebase, two hosts
The website is a Remix app. The same source builds for Vercel (npm run build) and for Cloudflare Workers (npm run build:cf). For the Workers build, Vite swaps out the modules that only work in Node.js. The Firebase Admin SDK, for example, is replaced by a small module that talks to Firebase's REST APIs using fetch and WebCrypto.
The Worker is set to fail open. If it hits its daily request limit, Cloudflare sends traffic to Vercel instead, and a script switches the primary host in one command.
Two lessons from running on Workers:
- Never share a Promise between requests. A module-level "request already in progress" Promise works fine in Node.js. On Workers, a Promise created in one request can't settle in another, so the second request fails. Module-level caches on our side store plain values only.
- Big files belong on a CDN. The AI model weights are several megabytes. They are served from
cdn.strangerly.in(the Worker's static assets) with a same-origin fallback, so they don't use up hosting bandwidth.
Cloudflare R2 stores report evidence privately. When you report someone, your device sends one frame and the last 30 chat lines. Those files are deleted automatically after 90 days unless they are needed for a ban.
Making the site fast
The landing page used to jump around while it loaded. Its Cumulative Layout Shift was 0.42, which is well into Google's "poor" range. The cause was that the layout adapted to screen size in JavaScript, and the server-rendered version always assumed a desktop. Phones rendered a desktop layout first and then changed it after the JavaScript loaded.
The fix:
- All responsive layout is done in CSS media queries, so the first render is already correct.
- The stylesheet and font declarations are inlined in the page head, with fallback fonts sized to match the real ones.
- Analytics loads only after the page has finished loading and the browser is idle.
In lab tests, layout shift dropped from 0.42 to 0. Real-user Web Vitals are sent to our analytics only when they are poor, so we can find the pages that need work without collecting data from every visit.
What we'd tell another small team
- Put the rules in pure functions and test both clients against the same examples. It is the only reason two codebases in two languages still behave the same.
- Know what your database charges for. Our biggest cost savings came from reading the bill, not from optimising code.
- Run AI on the device when you can. It is cheaper, it works without our servers, and it means we never see the video.
- Never assume a direct connection will work. On mobile networks in India, a TURN relay is required, not an extra.
If you want to see how all of this feels from the other side, start a chat. For what this means for your privacy, read our privacy policy and transparency page.
Frequently asked questions
Does my video go through strangerly's servers?
No. Video and voice go directly between the two devices over WebRTC. When a direct path is blocked, for example on many Indian mobile networks, the call goes through an encrypted relay that forwards the data without being able to see it. Nothing is recorded.
Where does the AI that checks for nudity run?
On your own phone or browser. The model is downloaded once and checks video frames locally. Only the outcome, such as blurring the video or a report you choose to send, ever leaves your device.
Can a web user and an app user be matched together?
Yes. The website and the Android app share the same backend and the same data format, so a person on a laptop can be matched with a person on a phone, and they can play the same games together.