<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Camdiv</title>
    <description>The latest articles on DEV Community by Camdiv (@camdiv).</description>
    <link>https://dev.to/camdiv</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3944397%2F25546622-c660-4b29-82ba-fadbbc46d202.png</url>
      <title>DEV Community: Camdiv</title>
      <link>https://dev.to/camdiv</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/camdiv"/>
    <language>en</language>
    <item>
      <title>How we moderate a live video-chat app in real time (without going broke on AI calls)</title>
      <dc:creator>Camdiv</dc:creator>
      <pubDate>Fri, 22 May 2026 18:45:22 +0000</pubDate>
      <link>https://dev.to/camdiv/how-we-moderate-a-live-video-chat-app-in-real-time-without-going-broke-on-ai-calls-2a71</link>
      <guid>https://dev.to/camdiv/how-we-moderate-a-live-video-chat-app-in-real-time-without-going-broke-on-ai-calls-2a71</guid>
      <description>&lt;p&gt;I work on &lt;a href="https://camdiv.com" rel="noopener noreferrer"&gt;Camdiv&lt;/a&gt;, an anonymous one-to-one video chat. You open the page, you get matched with a stranger, you talk. It's the Omegle-style format, and from the outside the hard part looks like the video: WebRTC, NAT traversal, keeping latency down.&lt;/p&gt;

&lt;p&gt;It isn't. WebRTC is mostly a solved problem. The hard engineering is moderation. You're putting two anonymous strangers on a live camera together, with almost no friction, and you have a few seconds to catch it if one of them does something that gets your platform pulled from every app store on earth.&lt;/p&gt;

&lt;p&gt;Three things shaped every decision below, and they fight each other the whole way. The first is cost: moderate live video naively and the bill alone will sink you. The second is false positives, because a wrong ban is a real person you just kicked off for nothing. The third took a near-miss to learn, so it gets the longest section here: you can't actually trust the video frame you're moderating.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why live anonymous video is the worst moderation surface
&lt;/h2&gt;

&lt;p&gt;Most moderation problems give you time. A user uploads a photo or writes a comment, and you can scan it before anyone else sees it. The content sits still while you decide.&lt;/p&gt;

&lt;p&gt;Live video gives you none of that:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;There's no upload step to gate. The stream is already happening.&lt;/li&gt;
&lt;li&gt;The content is ephemeral. By the time you've "reviewed" a frame, the next one is different.&lt;/li&gt;
&lt;li&gt;Anonymity plus zero signup friction means abuse is cheap and repeatable.&lt;/li&gt;
&lt;li&gt;You have seconds, not minutes. A human moderator can't sit on every one of thousands of concurrent streams.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So whatever you build has to be automated, run per frame, stay fast, and be cheap enough to run nonstop. Those goals do not sit comfortably together.&lt;/p&gt;

&lt;h2&gt;
  
  
  The pipeline
&lt;/h2&gt;

&lt;p&gt;The browser samples a JPEG from the local video every few seconds and sends it over Socket.IO to our backend. The backend forwards it to a separate moderation microservice (a small FastAPI app on its own host) over HTTPS, locked down with an internal shared key and an origin allowlist at the reverse proxy. The service runs the classifier and returns a compact verdict.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;flowchart LR
  A["Browser&amp;lt;br/&amp;gt;samples a JPEG every few seconds"] --&amp;gt;|Socket.IO| B["Backend&amp;lt;br/&amp;gt;Node / TypeScript"]
  B --&amp;gt;|"HTTPS + internal key&amp;lt;br/&amp;gt;origin allowlist"| C["Moderation service&amp;lt;br/&amp;gt;FastAPI, isolated host"]
  C --&amp;gt;|"verdict JSON:&amp;lt;br/&amp;gt;nsfw, minor, confidence, reason"| B
  B --&amp;gt; D{Act on the verdict}
  D --&amp;gt;|explicit| E[Confirmation + ban path]
  D --&amp;gt;|possible minor| F[Human review queue]
  D --&amp;gt;|safe| G[Do nothing]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Splitting moderation into its own service pays off in a few ways. A crash or memory spike in the ML host doesn't take the chat backend down with it. The two scale independently, since the Node app is I/O-bound and the moderation box is CPU- and GPU-bound. And the heavy model dependencies stay out of the application runtime, so a backend deploy doesn't have to drag a model toolchain along with it.&lt;/p&gt;

&lt;p&gt;The verdict shape is deliberately tiny:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"unsafe"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"minor"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"score"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mf"&gt;0.0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"reason"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"..."&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"source"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"gemini-safe"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Two independent booleans, a confidence score, and a short human-readable reason that lands in our logs. That &lt;code&gt;reason&lt;/code&gt; field has paid for itself many times over when I'm trying to work out why something did or didn't fire.&lt;/p&gt;

&lt;h2&gt;
  
  
  The cost wall, and why we schedule the model instead of running it on every frame
&lt;/h2&gt;

&lt;p&gt;Our moderator is a vision-language model (Gemini Flash Lite). Per call it's cheap. The trouble is the multiplication: concurrent users times a frame every few seconds is millions of calls a day. Run a VLM on all of them and the model bill, long before infrastructure, becomes the thing that kills the company.&lt;/p&gt;

&lt;p&gt;We started somewhere more conventional: an on-box NSFW CNN (NudeNet) with an escalation tier, where ambiguous scores got a second opinion from a hosted nudity API and Google Vision's SafeSearch. It worked. But it was three systems to keep healthy, and the CNN was biased: much better at detecting female anatomy than male, which is a real gap on a platform where most of the abuse is the latter.&lt;/p&gt;

&lt;p&gt;We replaced the whole thing with a single VLM because it reads context in a way a pure classifier can't. It can tell a shirtless guy on a couch from actual exposure. It handles the common trick of holding explicit content up on a phone to the camera. And it returns structured JSON I can trust to parse, with a built-in safety filter whose refusal to even describe an image is itself a useful signal.&lt;/p&gt;

&lt;p&gt;The cost math only works because of one decision: we don't moderate every frame. Each chat gets a small number of model calls, front-loaded into the first minute, and then we stop.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;flowchart TD
  F["Frame arrives for a match&amp;lt;br/&amp;gt;(session key = userId:roomId)"] --&amp;gt; Q{"Scheduled check due&amp;lt;br/&amp;gt;in this match's first minute?"}
  Q -- no --&amp;gt; S["Return safe — no model call"]
  Q -- yes --&amp;gt; R{"Within global rate&amp;lt;br/&amp;gt;and daily budget?"}
  R -- no --&amp;gt; S
  R -- yes --&amp;gt; C["One VLM call · consume the slot"]
  C --&amp;gt; V["Verdict: nsfw, minor, confidence"]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The premise, borne out by our logs, is that bad actors reveal themselves quickly. They don't behave for ten minutes and then flip. They flip in the first few seconds, because the reaction is the whole point for them.&lt;/p&gt;

&lt;p&gt;The part that matters is the session key. The schedule is keyed per match (&lt;code&gt;userId:roomId&lt;/code&gt;), not per user. Every new match starts a fresh schedule. Key it per user instead and someone could behave for their first 60 seconds, exhaust the schedule, then expose themselves to every later partner for free. Keying per match means partner #2 is a brand-new session with a brand-new set of checks. You can't outwait the system by being patient once.&lt;/p&gt;

&lt;p&gt;On top of the per-match schedule there are global backstops: a rate limit, a daily budget ceiling, one in-flight call per room, and a lock that dissolves a room's moderation the moment it returns an unsafe verdict. A bad chat costs exactly one billable model call instead of a flood of them.&lt;/p&gt;

&lt;h2&gt;
  
  
  The frame you can't trust
&lt;/h2&gt;

&lt;p&gt;Here's the section I'd tell my past self to read first.&lt;/p&gt;

&lt;p&gt;The model returns two independent flags: is this explicit, and does the person look like a minor. The naive enforcement rule writes itself: explicit plus minor equals instant permanent ban, no appeal, done.&lt;/p&gt;

&lt;p&gt;We deliberately don't do that, and here's the attack that taught us why.&lt;/p&gt;

&lt;p&gt;The frame we moderate is sampled and sent by a client. In a peer-to-peer video session, the bytes we classify can't be cryptographically proven to have come from the partner's live camera. A malicious client can send a frame of its own choosing. So if a single AI verdict on an unauthenticated frame triggered an instant permanent ban, any user could permanently ban any partner just by feeding our pipeline a chosen image. The most severe, least reversible action in the system would be trivially weaponizable by the person who stands to gain from it.&lt;/p&gt;

&lt;p&gt;So we split enforcement by how severe and how reversible the call is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;flowchart TD
  V["VLM verdict: nsfw, minor"] --&amp;gt; M{"Looks like a minor?"}
  M -- yes --&amp;gt; H["Human review queue&amp;lt;br/&amp;gt;(HIGH priority if also explicit)&amp;lt;br/&amp;gt;never an automatic ban"]
  M -- no --&amp;gt; N{"Explicit?"}
  N -- no --&amp;gt; OK["Safe · do nothing"]
  N -- yes --&amp;gt; CF{"Single frame at&amp;lt;br/&amp;gt;very high confidence?"}
  CF -- yes --&amp;gt; BAN["Enforce ban + capture evidence"]
  CF -- no --&amp;gt; ACC["Add to confidence over&amp;lt;br/&amp;gt;a short rolling window"]
  ACC --&amp;gt; T{"Evidence adds up?"}
  T -- yes --&amp;gt; BAN
  T -- no --&amp;gt; WAIT["Wait — no action yet"]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Anything that flags a possible minor goes to a human review queue and is never auto-banned, however confident the model is. A person makes that call, looking at captured evidence, because the cost of getting it wrong in either direction is too high to hand to a script. Explicit-but-adult content goes through the confirmation path below.&lt;/p&gt;

&lt;p&gt;If you take one thing from this post, take this: in any system where the input can be shaped by the party who benefits from the outcome, an automated decision is an attack surface. Authenticate the input before you automate the verdict.&lt;/p&gt;

&lt;h2&gt;
  
  
  Not banning the wrong people
&lt;/h2&gt;

&lt;p&gt;Even for clear-cut explicit content, one frame shouldn't end someone's session. Cameras produce garbage: bad lighting, a weird angle, a half-second of motion blur that a model misreads.&lt;/p&gt;

&lt;p&gt;So a single frame only acts immediately if it comes back at very high confidence. Below that bar, we add up confidence across a short rolling window and act only once the evidence agrees with itself. A one-off false flicker never reaches the threshold. A genuinely explicit stream trips it almost at once, because frame after frame says the same thing.&lt;/p&gt;

&lt;p&gt;We check three signals when we ban: IP, a device fingerprint, and the account (sign-in is Google, with an age-verification gate). Stacking them makes coming back more than a one-click affair, without banning everyone behind a shared NAT because of one person.&lt;/p&gt;

&lt;h2&gt;
  
  
  Reports, without taking them at face value
&lt;/h2&gt;

&lt;p&gt;Users can report each other. We treat a report as a signal, never as a verdict, because a report is weaponizable too.&lt;/p&gt;

&lt;p&gt;Image reports (nudity, suspected minor) get validated by the model. We send the reported snapshot through the classifier, bypassing the schedule since a human explicitly asked us to look, and let that be the source of truth. High-confidence explicit gets enforced, borderline goes to human review, suspected-minor always goes to human review, and a clean frame quietly drops the report.&lt;/p&gt;

&lt;p&gt;Reports we can't check with an image model, like verbal or racial abuse, work differently. There we use a weighted score: independent reporters each add weight to a target, and a ban only triggers once enough distinct people report the same person inside a window. One furious stranger can't get you banned. A pattern of them can.&lt;/p&gt;

&lt;h2&gt;
  
  
  Failing open, on purpose
&lt;/h2&gt;

&lt;p&gt;Eventually your moderation service will be unreachable. A deploy, a crash, a network blip. You have to decide ahead of time what happens to live chats during that window: block everyone, or let them through?&lt;/p&gt;

&lt;p&gt;We chose to fail open, behind a circuit breaker. After several failures in a row the backend trips the breaker, stops hammering the dead service for a cool-off period, then sends one test call to see if it's back. While it's tripped, chats keep flowing unmoderated.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;stateDiagram-v2
  [*] --&amp;gt; Closed
  Closed --&amp;gt; Open: consecutive failures exceed threshold
  Open --&amp;gt; HalfOpen: cool-off elapsed
  HalfOpen --&amp;gt; Closed: test call succeeds
  HalfOpen --&amp;gt; Open: test call fails
  note right of Closed: calls flow normally
  note right of Open: skip moderation,&amp;lt;br/&amp;gt;chats continue
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It's an uncomfortable tradeoff and I won't pretend otherwise. It's only defensible because of what's around it: the per-match schedule re-checks every new pairing, user reports keep working, the face-presence gate still runs, and every action is logged so we can act after the fact. Failing closed, which freezes everyone's video the instant the ML box hiccups, is its own kind of harm, and on a real-time product it's the more visible one. Pick your failure mode on purpose. Don't let it be an accident of which &lt;code&gt;try/catch&lt;/code&gt; you forgot.&lt;/p&gt;

&lt;h2&gt;
  
  
  Due process: evidence and appeals
&lt;/h2&gt;

&lt;p&gt;Automated enforcement gets things wrong sometimes. Ship it without a way to be wrong gracefully and you've built something you'll regret.&lt;/p&gt;

&lt;p&gt;So every ban captures the triggering frame as evidence and stores it server-side. Every ban is appealable. An admin reviews the evidence and either upholds or overturns it, and overturning also deletes the stored evidence. Bans persist with their trigger, confidence, and reason, so there's an audit trail. The appeals queue isn't something you bolt on later. It's part of the enforcement system, and having it is what lets you turn the automation up at all.&lt;/p&gt;

&lt;h2&gt;
  
  
  What's still hard
&lt;/h2&gt;

&lt;p&gt;I don't want to end on a victory lap. A few things here are genuinely unsolved for us:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;We still can't prove a frame came from the real camera stream. That's the root cause of the weaponization problem above, and in browser WebRTC it's a hard one. We mitigate it; we haven't solved it.&lt;/li&gt;
&lt;li&gt;We moderate video, not audio. Purely verbal abuse only gets caught through reports.&lt;/li&gt;
&lt;li&gt;Adversarial timing is an arms race. The per-match reset raises the cost of gaming the schedule, but a determined actor still probes it.&lt;/li&gt;
&lt;li&gt;How many checks to run, how far to front-load them, where to set the budget ceiling: that's a knob we'll be turning forever, not one we got right on day one.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;What keeps me interested is that almost none of this is about video. It's about building enforcement cheap enough to run nonstop, accurate enough to trust with real consequences, and fair enough that the appeals queue doesn't make you wince. If you want to see where it ends up, it's live at &lt;a href="https://camdiv.com" rel="noopener noreferrer"&gt;Camdiv&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Happy to go deeper on any piece in the comments. The scheduling math and the fail-open call are the two I'd most like to be argued with about.&lt;/p&gt;

</description>
      <category>webrtc</category>
      <category>ai</category>
      <category>python</category>
      <category>typescript</category>
    </item>
  </channel>
</rss>
