Hot shard (celebrity problem): One shard is at 100% CPU while the other three are idle
Hot shard (celebrity problem) debugging lab. The users table is sharded across 4 shards by user_id % 4. A famous singer joined; now shard 2 is pegged and profile loads for normal users on that shard time out.
Practice debugging a hot shard (celebrity problem) in a live, broken production system in your browser, with PostgreSQL. Find the root cause in the logs, terminal and code, fix it, and a load test checks that the fix holds under real traffic.
1. The Incident Context
The users table is sharded across 4 shards by user_id % 4. A famous singer joined the platform, and now shard 2 is at 100% while shards 0, 1 and 3 sit idle. Profile loads for normal users on shard 2 time out.
2. Observed Symptoms & Metrics
- Affected Endpoints / Components:
GET /users/:id, the four user shards.
- Behavior: About 90% of traffic is fans loading one profile. That user maps to shard 2, so shard 2 handles almost all traffic, and every normal user who also maps to shard 2 suffers.
- Error Rate: Normal users on shard 2 time out; the celebrity's own profile still loads, slowly.
- System Metrics: Shard 2's connection pool is pinned at 4/4 with a long wait queue. The other three shards are idle.
3. Application Logs
19:02:02 profiles service listening on :8080
19:02:40 shard_2 pool: 4/4 connections in use, 120 waiting
19:02:41 GET /users/6 took 3,800ms (shard_2)
4. Your Objective
Step into the live environment while synthetic traffic is running, diagnose the root cause, and patch the codebase.
To clear this stack, your fix must satisfy these automated verification checks under a 60-second celebrity traffic spike:
- Hot shard: Normal users on the celebrity's shard stay below 300 ms p99.
- Availability: Both the celebrity and normal users keep loading.
Toolbox: curl localhost:8080/users/2, curl localhost:8080/users/6, psql "$DATABASE_URL", the app logs.
The shard is chosen only by user_id % 4, so the celebrity shares a shard with thousands of normal users. Give celebrities a dedicated shard and route them there.
Save a file in the editor to rebuild and restart the app. Click Verify when you think it's fixed.
Your account and data
You can browse stacks without an account. To run labs you sign in with your email or Google account. BustedStack uses your email address to
sign you in, and your name and profile picture to show your account and pre-fill certificates. We never access your Gmail, contacts or Drive,
sell your data or run ad trackers.
Privacy Policy · Terms of Service · Browse stacks ·
hello@bustedstack.com
This site needs JavaScript to run labs.