Lock held during I/O debugging lab. CPU is idle and the rate provider is fast enough, yet the FX service can't keep up with the pricing page.
Practice debugging a lock held during i/o in a live, broken production system in your browser, with Go. Find the root cause in the logs, terminal and code, fix it, and a load test checks that the fix holds under real traffic.
> Go only. This stack is about how Go code behaves when many requests run at once, so it ships in Go alone.
1. The Incident Context
The pricing page converts every price into the shopper's currency through the FX service. Last sprint a refactor added an in-memory cache of exchange rates, and since then the FX service tops out at a handful of requests per second. Adding CPU did nothing. The storefront sends it 80 requests per second.
2. Observed Symptoms & Metrics
- Affected Endpoints / Components:
GET /convert?from={ccy}&to={ccy}&amount={n} on the FX service. It gets rates from the upstream rate provider at localhost:9100, which takes about 200 ms per call.
- Behavior: One request on its own takes about 2 ms when the rate is cached, or about 200 ms when it isn't. Under load, latency grows with the queue to several seconds, even for currency pairs that are already cached.
- Error Rate: Most requests hit the storefront's 2 s timeout.
- System Metrics: App CPU stays under 5%. The rate provider is healthy and answers every call in about 200 ms. A goroutine dump shows hundreds of goroutines waiting in
sync.(*Mutex).Lock inside RateCache.Get, and one goroutine waiting on localhost:9100.
3. Application Logs
2026/10/12 15:10:00 fx service listening on :8080
# curl 'localhost:8080/debug/pprof/goroutine?debug=1' | head
goroutine profile: total 412
398 @ ... sync.(*Mutex).Lock
# main.(*RateCache).Get rates.go:37
1 @ ... net/http.(*persistConn).roundTrip
# main.(*RateCache).fetchRate rates.go:57
# k6
http_req_failed................: 87.29%
http_req_duration..............: avg=1.84s p(95)=2.00s p(99)=2.00s
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 80 req/s across 30 currency pairs, with rates expiring every 10 seconds:
- Error Rate: Fewer than 1% of requests fail (
http_errors < 1%).
- Performance: P99 latency stays below 300 ms (
p99_latency_ms < 300).
- Data Integrity: Every conversion uses the provider's real rate, no more than 10 seconds old, and the answer equals amount × rate (
checks_fails == 0).
- Upstream Load: The rate provider is called at most twice per currency pair in any 10-second window (
upstream_calls_per_pair_window <= 2).
Toolbox: curl 'localhost:8080/convert?from=USD&to=EUR&amount=100', curl 'localhost:8080/debug/pprof/goroutine?debug=1' | head -40, curl localhost:9100/stats, htop. Save a file in the editor to rebuild and restart the app. Click Verify when you think it's fixed.
Terms in this lab: FX (foreign exchange, currency conversion), req/s, p99, CPU, goroutine, mutex, pprof, k6.
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.