DEV Community

Cover image for Performance vs scalability: why the fast server loses
System Design Simple
System Design Simple

Posted on Originally published at systemdesignsimple.com

Performance vs scalability: why the fast server loses

Answer first: a server that is fast for one user can be slow for a hundred, because latency under load is mostly waiting, not working.

We tested two versions of the same endpoint. Version A does 5 ms of work, but every request needs the one database connection the process holds. Version B does 15 ms of work and borrows from a pool of 50 connections.

With one user, A wins: median 5.2 ms against 15.2 ms for B. With 10 users, A is already slower: 50.2 ms against 15.2 ms. With 100 users, A hits a median of 498.1 ms while B stays at 29.8 ms. At 500 users, 1,196 of 2,000 requests to A hit the 1 second pool wait timeout. B had zero timeouts.

Two formulas predict all of this. The throughput ceiling is connections divided by work per request: A tops out at 1 / 0.005 s = 200 requests a second, B at 50 / 0.015 s = about 3,333. The response time law says response time equals users divided by throughput, so once A is pinned at its ceiling, each extra user adds 5 ms of waiting.

The lesson is not that pools should be huge. A pool only helps if the thing behind it can do that much work at once. PostgreSQL runs one process per connection and defaults to 100 connections, so raising the pool past what the server can run in parallel makes each query slower. Size the pool from measured query time: busy connections on average equal queries per second times time per query.

To find the bottleneck in your own system, look for saturation, not speed. Record utilisation and queue length for each resource, find the largest demand per request, then confirm with a step test: raise concurrency in steps and watch whether throughput flattens near the predicted ceiling while latency grows by the same amount per added user.

Our numbers come from a discrete event simulation in Node.js with a fixed seed, 2,000 requests per level, no real database or network. It shows the shape of queueing behaviour, not the capacity of any production system.

Read the full article, with the tables, the diagrams and the pool sizing math, on System Design Simple: https://systemdesignsimple.com/fast-alone-slow-crowded/

Top comments (0)