Designing a Bot Dispatch Service for Joining Online Meetings
System DesignModel answerLast updated
Design the backend between a web UI and a pool of meeting-joining bots that safely assigns bots, tracks session state, and recovers from failures at 100K concurrent sessions.
Bot Dispatch for Online Meetings
A product lets users paste a meeting link (Zoom, Google Meet, Teams, WebEx and similar) into a web page. A bot from a shared pool must then join that meeting, and the user must see the bot's progress live in the browser.
The web UI and the bots already exist. You are designing the service in the middle: it accepts requests, assigns bots, tracks session state, and pushes updates back to the UI.
Functional requirements
- A user submits a meeting URL and, optionally, credentials (for example a passcode or a login for the meeting).
- The service acknowledges the request asynchronously; the user does not wait for the join to complete.
- Exactly one idle bot is assigned to each request. Assignment must be atomic, so two requests never get the same bot and one request never gets two bots.
- The user sees the session move through states such as
queued,assigned,joining,joined, and finally one offailed,disconnected, orended.
Scale
- Up to 100,000 concurrent meetings.
- About 1 million meetings per day.
Reliability constraints
- Once a request is acknowledged, it must never be silently lost.
- Messages can be delivered more than once.
- Bots can crash or lose connectivity in the middle of a session.
What to cover
Walk through requirements and clarifying questions, the API, the data model, how you keep assignment consistent, how you scale, how you recover from failures, how you handle running out of bots, and how you observe the system. Call out the main trade-offs.
Questions worth raising with the interviewer: Are credentials stored or just passed through? How fresh must the state shown in the browser be?
Hints
Hint 1
Persist the request before you acknowledge it, then drive everything else from that durable record. Think about what the acknowledgment actually promises.
Hint 2
Treat bot ownership as a time-limited lease that the bot must keep renewing with heartbeats. A missed renewal is how you detect a dead bot without guessing.
Hint 3
Assume every message can arrive twice. Give each request an idempotency key and make every state transition a conditional update, such as compare-and-set on a version or current state.
Hint 4
Separate the control plane (requests, assignments, state) from the streaming path to the browser, and size them separately: 1M/day is about 12 requests per second on average, but 100K live sessions means a lot of long-lived connections and heartbeats.
Model answer
Medium Try it yourself first — then compare your approach, complexity and edge cases.
Clarifying questions and assumptions
- Credentials: assume they are sensitive. Do not keep them in plain text in logs or the main database. Store them encrypted with a short TTL (a secrets manager or an encrypted column with a per-record key), and delete them once the session is
joinedor terminal. The alternative of pure pass-through is only viable if the request never needs a retry, and it does, so short-lived encrypted storage is the realistic choice. - State latency: assume a second or two is fine for the UI. That allows server-push over WebSocket or SSE without extreme tuning.
- Load: 1M/day is about 12 requests/s on average, perhaps 50 to 100/s at peak. The harder number is 100K concurrent sessions. If each bot heartbeats every 15 to 30 s, that is roughly 3K to 7K heartbeats/s, plus state changes and 100K open browser streams.
- Pool size is at least 100K bots. Assume the pool can scale in and out.
API
POST /sessionswith{meeting_url, credentials?}and anIdempotency-Keyheader. It returns202 Acceptedwithsession_idafter the request is durably stored. A retry with the same key returns the samesession_id.GET /sessions/{id}returns the current state.GET /sessions/{id}/eventsis an SSE or WebSocket stream of state changes, withLast-Event-IDfor resume.DELETE /sessions/{id}asks the bot to leave.- Internal bot API:
register,heartbeat(lease),report_state(session_id, state, version).
Data model
- sessions:
session_id,idempotency_key(unique per user),user_id,meeting_url,state,version,bot_id,lease_expiry,attempts,created_at,updated_at,failure_reason. - bots:
bot_id,status(idle,busy,draining,dead),current_session,last_heartbeat. - session_events: an append-only log of transitions, used for the UI stream, audit, and replay.
- credentials: encrypted, keyed by
session_id, with TTL.
A sharded relational store or a strongly consistent key-value store both work. Shard by session_id. Rows are small and the write rate is modest, so this is not the bottleneck.
Core flow
- The API writes the session row (
queued) and an outbox entry in one transaction, then returns 202. Nothing is acknowledged before this commit, which is what satisfies "never silently lost". - A relay publishes outbox entries to a durable queue (Kafka, SQS, or similar). Publishing is at-least-once.
- A dispatcher consumes the queue and picks an idle bot.
- Atomic assignment: a conditional write such as
UPDATE bots SET status='busy', current_session=? WHERE bot_id=? AND status='idle'. Only one writer can win. The session is updated in the same transaction (or with a version check) toassignedwith a lease expiry. If the conditional write fails, try another bot. A common structure is a free-list per region or platform (a Redis set or a pool table) from which the dispatcher pops candidates, with the database conditional update as the source of truth. - The dispatcher sends the bot a job (
session_id,attempt). The bot callsreport_stateas it goes throughjoiningandjoined. - While active, the bot renews its lease by heartbeat. Terminal states release the bot back to
idle.
Consistency and idempotency
- Every transition is a compare-and-set on
(session_id, expected_state or version). Duplicate or late messages become no-ops. - Consumers are idempotent: processing
session_idtwice must not assign a second bot. The check is "if the session is notqueued, ack and skip". - Bot messages carry an
attemptnumber, so reports from a previous, presumed-dead bot are rejected (fencing token). This prevents a zombie bot from overwriting the new owner's state.
Failure handling
- Bot crash or network loss: the lease expires with no heartbeat. A reaper (a periodic scan or delay queue keyed on
lease_expiry) marks the botdead. If the session had not yet reachedjoined, it is requeued withattempts+1. If it was already in the meeting, the bot is gone, so the state becomesdisconnected, and policy decides whether to automatically rejoin. - Dispatcher crash mid-assignment: the conditional write plus the lease means a half-finished assignment either completes or expires and is retried.
- Join failures (wrong passcode, meeting not started, waiting room): classify them as retryable or permanent. Retry with exponential backoff and jitter up to a cap, then
failedwith a reason. - Queue or database outage: the API fails fast with 503 rather than acknowledging something it did not persist. The outbox ensures messages are republished after recovery.
- Poison messages: after N attempts, move them to a dead-letter queue and alert.
Capacity exhaustion
- Sessions stay
queuedwith an estimated wait shown to the user. Queue depth drives autoscaling of the bot fleet, with headroom (say 10 to 20%) because bot start-up takes time. - Apply per-user and per-tenant quotas and admission control, so one tenant cannot starve others. Use priority queues if there are paid tiers.
- If the queue wait exceeds a deadline, expire the request with a clear error instead of leaving it in limbo.
Streaming states to the browser
State changes append to session_events and are published on a pub/sub channel (for example Redis streams or Kafka). A stateless gateway tier holds the WebSocket or SSE connections, with roughly 10K to 50K connections per node, so 100K streams needs only a handful of nodes plus redundancy. Clients reconnect with the last event id and replay missed events. Fall back to polling GET /sessions/{id} if streaming is unavailable.
Observability
- Metrics: queue depth and age of oldest item, time from request to
joined(p50/p95/p99), join success rate by platform, lease-expiry rate, idle bot count, retry and DLQ counts, stream connection count. - Structured logs and traces tagged with
session_id, with no credentials in them. - Alerts on rising queue age, falling join success for one platform (often a platform UI change), and heartbeat gaps across many bots at once (often a network or deploy problem).
Trade-offs
- Lease length: short leases detect failure faster but increase heartbeat load and false positives from brief network blips. 30 to 60 s is a typical compromise.
- At-least-once plus idempotency is far simpler than trying for exactly-once delivery.
- Push vs pull assignment: letting idle bots pull work scales simply and avoids a central bottleneck, while central dispatch gives better placement control. Either works at this scale.
- Warm pool vs on-demand bots: a warm pool lowers join latency but costs money when idle.
Common mistakes
- Acknowledging the request before it is durably stored.
- Assigning with read-then-write instead of an atomic conditional update.
- No fencing, so a zombie bot corrupts state after reassignment.
- Storing credentials in logs or long-term plain text.
- Unbounded retries with no backoff, which turn one outage into a retry storm.
- Ignoring the "pool is empty" case.