Lessons › From one user to millions
Five million people online
Your chat app has 5 million people online at the peak. They make 5,000 requests a second, and 1,500 of those are new messages. Every one of them holds a connection open, even when nobody's typing.
Play this levelFree with an account. It runs in your browser: build the design, press Run, and watch what breaks.
The lesson
A normal request comes and goes. Chat, live scores and notifications need the server to speak first, so each user keeps a WebSocket open. The limit stops being requests per second.
Here the limit is how many stay connected. API Gateway closes a WebSocket after two hours, and by default allows 500 new connections a second. That's about 3.6 million open at once: AWS's own worked example.
You also pay for silence. At $0.25 per million connection minutes, a user sitting idle costs more than the messages they send.
If the 500 limit is too low you can ask for more. This level uses the default, so run a second gateway.
What you have to achieve
5,000 requests a second at the busiest hour, 30% of them writes.
- No broken or illegal connections
- Use a Realtime Gateway
- Hold 5M open connections
- No component is overloaded
- Fewer than 0.1% of requests fail
- p99 response time under 150 ms
What you learn
Look at Monthly cost: most of it pays for connections that sit quiet, not for messages. At this size it's often cheaper to run your own WebSocket servers, and that's a real trade: more to run, less to pay. Worth checking before you build.
Check yourself
In a chat app, what becomes the limit instead of requests per second?
- Message size
- Disk space
- How many people stay connected
Show the answer
How many people stay connected. Each user holds a WebSocket open, even when quiet. Open connections are the scarce thing.
What did most of the bill pay for?
- Connections that sit quiet
- Messages sent
- The database
Show the answer
Connections that sit quiet. At $0.25 per million connection minutes, an idle user costs more than the messages they send.