KatInterview

Investigating Latency Spikes After Traffic Doubles

System DesignModel answer
MediumModel answerSystem Designperformanceobservabilitydistributed-systems

Last updated

Diagnose and resolve severe performance degradation in a distributed system after user load doubles, using observability and root-cause analysis.

Context

Your team operates a web-based task tracking platform. After migrating several major customers onto your infrastructure, the active user base grew from 5 million to 10 million daily active users, and request volume increased from 50,000 requests per second to 100,000 requests per second.

Users now report that the application feels significantly slower. Your monitoring reveals that the primary endpoint for loading work items (GET /api/v1/projects/{projectId}/board) shows alarming degradation:

  • Median latency increased from 40ms to 180ms
  • 95th percentile latency jumped from 120ms to 2,100ms
  • 99th percentile latency spiked from 250ms to 5,400ms
  • Gateway timeout errors (HTTP 504) reached 3.2%

Your application servers show modest resource consumption: average CPU at 42% and memory at 55%. Yet the database connection pools frequently reach their limit, and your Redis cache cluster shows eviction rates that are four times higher than before.

Architecture Overview

Your stack consists of:

  1. Edge Layer: CDN and reverse proxies distribute traffic to regional API gateways
  2. Application Layer: Stateless services (Go and Java) running in Kubernetes handle business logic, authorization, and data aggregation
  3. Cache Layer: Redis cluster storing session state, tenant settings, and preprocessed work item data
  4. Storage Layer: PostgreSQL primary-replica cluster for structured data, plus Elasticsearch for full-text search

Your Task

Explain how you would investigate this performance collapse and restore healthy operation. Cover:

  1. Immediate Stabilization: What actions would you take in the first hour to reduce impact on users while investigation continues?

  2. Investigation Approach: Which specific metrics, traces, and logs would you examine to pinpoint the bottleneck? Describe your methodology for isolating the failure tier.

  3. Root Cause Hypotheses: Analyze potential failure modes across application runtime (threading, garbage collection, connection management), caching (memory pressure, hot keys, invalidation patterns), and database (query performance, connection exhaustion, replication lag).

  4. Permanent Resolution: Propose architectural and implementation changes that will support the increased scale without recurring issues.

Hints

Hint 1

Low CPU usage with high latency suggests threads are waiting, not computing—what shared resources do they wait for?

Hint 2

A 2× traffic increase causing 50× worse tail latency points to a nonlinear relationship—what could amplify load in this way?

Hint 3

Consider how the arrival of large customers might differ from your previous workload in data size and query patterns.