Skip to content
RED SAGSkills
hardBackend Developer interview question

Design the backend for a real-time chat app with one-to-one and group chats, online status and message history.

What the interviewer wants to hear

  • Persistent connections with WebSockets through gateway servers
  • Routing messages between gateways with pub/sub and a presence store
  • Message storage partitioned by conversation, with ordered ids
  • Delivery guarantees: client ids for dedup, acks, sync on reconnect
  • Offline users get push notifications; large groups need fan-out strategy

Model answer

Clients keep a WebSocket open to a fleet of stateless gateway servers behind a load balancer. A presence store in Redis maps each online user to their gateway and expires entries via heartbeats. When a user sends a message, it carries a client-generated id for deduplication. A chat service validates membership, assigns an ordered per-conversation id, and writes it to a store partitioned by conversation id, such as Cassandra, ScyllaDB or sharded PostgreSQL, then acks the sender. It publishes the message through pub/sub, for example Redis or NATS, to the gateways of online members. Offline members get a push notification. On reconnect, clients ask for everything after the last id they saw, so missed messages are never lost. For very large groups I would fan out on read instead of pushing to every member, and I would rate limit senders to prevent spam.

Can you answer it under time pressure?

Take a timed hard round and get scored on every answer.

Start mock interview

More hard Backend Developer questions