Designing a 12-Seat Voice Room: WebRTC/SFU, Server-Authoritative Coins, and Moderation
Social voice rooms look simple: a grid of 10–12 mic seats, a chat strip, some gift animations. Underneath, they combine three hard problems — real-time media, money, and trust & safety. Get any one wrong and the room either lags, leaks money, or turns toxic. This post walks through a practical design for a multi-seat voice room: how to route audio, how to keep a virtual-coin economy honest, and…
Designing a voice room with 12 mic seats, chat, and gifts is a complex task. It combines three hard problems: real-time media, money, and trust & safety. The architecture uses an SFU (Selective Forwarding Unit) to route audio streams efficiently. The SFU forwards audio packets to subscribers without decoding, which makes it a good fit for voice rooms.
Only seated users have publishing permission, while everyone else is receive-only. This helps in managing the number of audio tracks and reduces the computational burden on the server.
The server is responsible for managing the seats, which is shared state for the room. All seat changes go through the backend as commands, ensuring that client and server permissions are in sync. The backend validates permissions, applies changes atomically, and broadcasts the updated state over the signaling/data channel. Clients render the state, but never mutate it locally. This approach ensures that kicked users cannot keep talking.
Coins and gifts are handled server-authoritatively. Clients send gift intents, and the server checks the sender's balance, debits the sender, credits the receiver, and writes immutable ledger rows. Idempotency keys are used to prevent multiple gifts from being sent due to network retries. The ledger serves as the source of truth for balances, and a double-entry ledger is kept for auditing and dispute handling. Idempotency keys are also used to avoid multiple gifts from being sent due to network retries.
Moderation is a crucial aspect of voice rooms as it is ephemeral. The moderation features are built into the architecture, with role model tokens granting permissions to admins, seated speakers, and listeners. Host tools allow muting, removing, kicking, and locking seats. Text chat filtering is run through a service before broadcasting, and listeners can filter the chat view. Reporting and an audit log are kept for moderation actions and reports, which helps in resolving disputes.
The architecture separates media, room state, and money into separate services. Media scales horizontally by room, while room state needs low-latency pub/sub. The wallet service keeps a SQL ledger for transactions. Payment webhooks are used to credit coin purchases only after a verified payment-provider webhook or receipt validation. The services are kept separate to ensure scalability and maintainability.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.