Video in progress
How do you plan capacity and organize load testing for a real-time platform? How does it differ from HTTP load testing?
The main measures aren't RPS but concurrent connections, connection setup rate, and broadcast fan-out. The test must hold connections for a long time, simulate a reconnect storm, and measure latency on the client side.
📖 Answer
An HTTP load test works with "N requests per second, p99 latency". WebSocket has no notion of a request. I measure separately:
- Steady state. N connections are open, each receiving and sending messages at a realistic rate. I watch node RSS memory, GC pauses, CPU and end-to-end latency.
- Connect rate. How many new connections per second get established (TLS + handshake + auth + initial state). This usually breaks well before steady state, especially the TLS and auth service.
- Reconnect storm. We kill one node. Its clients move to the remaining nodes. How long does the system take to recover, and which link saturates (often the DB or auth)?
- Broadcast spike. One event to 1 million subscribers. The fan-out time and the queues after it.
- Soak test. 12 to 24 hours. Memory leaks (unclosed sessions, dead emitters) show up only then.
Tools: Gatling and k6 support WebSocket. One generator machine is limited by ephemeral ports and CPU, so you need several machines or several source IPs. To measure latency I put the server time inside the message and take the difference on the client; the clocks must be synchronized with NTP, otherwise look at relative change.
The planning formula is roughly:
node count = max(
peak_connections / node_connection_capacity,
peak_msgs_out_per_sec / node_msgs_capacity,
reconnect_rate_after_node_loss / node_connect_capacity
) * (1 + headroom)
Most people forget the third line. Sometimes it's the one that determines the node count: with few nodes, losing one brings too many reconnects to the others.
And learn from prod: measure how many messages real clients send, how long connections live and what the mobile share is, and adapt the test to that. A synthetic "everyone sends one message a second" is often far from reality.
Sign up to mark studied questions and save your progress.