Unusable index debugging lab. Every login got a little slower each week. The email column has had an index since launch, and Postgres is pinned at 95% CPU.
Practice debugging a unusable index 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
Login p99 has gone up a little every week since the marketing campaign started. This morning at 08:30 a promo email sent a burst of users to sign in, and login crossed its SLO. The DBA says users.email has had an index since launch, and \d users agrees.
2. Observed Symptoms & Metrics
- Affected Endpoints / Components:
POST /login on the auth service, Postgres users table (400,000 rows).
- Behavior: On an idle system a single login takes about 180 ms. At 60 req/s, requests queue up behind the database and latency climbs past 1 second. Login time grows in step with the number of users.
- Error Rate: During bursts, logins that take longer than 3 s fail with
503.
- System Metrics: Postgres CPU sits at 95%. In
pg_stat_user_tables, seq_scan on users rises by thousands per minute while idx_scan stays flat. The app itself is mostly idle, waiting on Postgres.
3. Application Logs
2026/10/12 08:30:00 applied migration 001_users_email_index.sql
2026/10/12 08:30:00 auth service listening on :8080
# psql: \d users
Indexes:
"users_pkey" PRIMARY KEY, btree (id)
"users_email_idx" btree (email)
# psql: SELECT seq_scan, idx_scan FROM pg_stat_user_tables WHERE relname = 'users';
seq_scan | idx_scan
----------+----------
41822 | 0
# slow query log
duration: 176.412 ms statement: SELECT id, password_hash FROM users WHERE lower(email) = lower($1)
# k6
http_req_duration..............: avg=890ms p(95)=1.71s p(99)=2.44s
4. Your Objective
Step into the live environment while synthetic traffic is running, find the root cause, and patch the code.
To clear this stack, your fix must pass these checks under a 60-second load test at 60 logins/s:
- Error Rate: Fewer than 1% of requests fail (
http_errors < 1%).
- Performance: P99 latency stays below 100 ms (
p99_latency_ms < 100).
- Data Integrity: All 400,000 users are still in the database, every correct login returns the right user, and login stays case-insensitive:
Alice@Example.com, alice@example.com and ALICE@EXAMPLE.COM all log in to the same account (data_integrity).
Environment note: schema changes go in migrations/. The app runs every .sql file there, in name order, each time it starts, so write them to be safe to run again (IF NOT EXISTS).
Toolbox: curl -X POST localhost:8080/login -H 'Content-Type: application/json' -d '{"email": "User7@Example.com", "password": "hunter2"}', psql "$DATABASE_URL" (try EXPLAIN ANALYZE, \d users, pg_stat_user_tables). Save a file in the editor to rebuild and restart the app. Click Verify when you think it's fixed.
Terms in this lab: p99, req/s, SLO (Service Level Objective, the latency target the team promised), DBA (Database Administrator), CPU, EXPLAIN ANALYZE (runs a query and shows how Postgres executed it), seq scan (reading every row of a table), btree (Postgres's default index type).
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.
This site needs JavaScript to run labs.