On-Call Playbook: Memory Alarm in a Card-Funding Service
System DesignModel answerLast updated
Walk through how you would triage, diagnose, mitigate, and follow up on a memory alert in a service that funds couriers' payment cards via a third-party provider and a Redis cache.
Scenario
You are the on-call engineer for a food and goods delivery platform.
How the system fits together
- Couriers use a mobile app to pick up and complete deliveries.
- The app talks to a public-facing gateway, the
Courier Gateway. - The gateway calls an internal
Card Funding Service. - For certain merchants, couriers must pay at the counter with a prepaid debit card. The card is loaded with money programmatically at checkout through an external card-issuing provider.
- The funding service keeps card and account data in a Redis cache.
- The company is partway through moving from a monolith to microservices.
Courier App -> Courier Gateway -> Card Funding Service -> External Card Provider
Card Funding Service <-> Redis
The page
It is 4:30 PM Pacific, right as the dinner rush is ramping up. You receive an alert: the Card Funding Service has memory utilization well above its normal level.
What to deliver
Describe how you would run this investigation from the first page to the post-incident review. Cover each of the following:
- How you would judge severity and business impact.
- Which metrics, dashboards, and logs you would look at first.
- The most probable causes of high memory in this particular architecture.
- How you would tell apart traffic growth, a recent deploy, Redis problems, retry amplification, and a slow or failing provider.
- Immediate mitigations you would consider, and their risks.
- How you would communicate while the incident is in progress.
- Longer-term fixes and follow-up work after recovery.
Hints
Hint 1
High memory is a symptom. Before digging into causes, decide whether couriers and orders are actually being hurt, and how much time you have before pods get OOM-killed.
Hint 2
Look at the shape of the memory curve: a step change at a deploy time, a sawtooth with a rising floor (leak), growth proportional to request rate, or growth that begins right after provider latency rises each point to a different cause.
Hint 3
Compare inbound request rate to outbound provider calls, check Redis hit ratio and latency, and compare pods against each other. Capture a heap dump from one pod before restarting anything. Note that scaling out can worsen a slow-provider problem.
Model answer
Medium Try it yourself first — then compare your approach, complexity and edge cases.
Guiding principle
Protect the business first, debug second. Gather evidence before acting, change one variable at a time, communicate continuously, and make sure the same failure cannot recur silently.
1. Severity and business impact
High memory is a symptom, not necessarily an outage. First I want to know whether it is hurting anyone.
- Timing amplifies impact. 4:30 PM Pacific is the start of the dinner peak, so any degradation is multiplied by order volume.
- The path is business critical. If a card cannot be funded, a courier is stuck at a counter. That leads to cancelled or delayed orders, wasted food, refunds, support spikes, and lost courier trust.
- User-facing signals to check immediately: funding success rate, checkout latency (p50/p99), 5xx rate at the gateway, and OOMKilled events or crash loops.
- Headroom. If pods are at 85% of their limit and growing 2% per minute, I have roughly minutes, not hours.
| Situation | Severity |
|---|---|
| Memory high but flat, no errors or latency change | Low: investigate with urgency, no incident yet |
| OOM restarts, rising latency, falling funding success | High: declare an incident now |
| Funding failing broadly at peak | Critical: escalate, pull in more responders |
2. First things to look at
- Service health: memory per pod (RSS versus heap), GC frequency and pause time, restarts, OOMKills, CPU (GC thrash shows as high CPU).
- Load and concurrency: requests per second, in-flight requests, thread/goroutine counts, queue depth, connection pool usage.
- Change history: deploys, feature flags, config changes, infra changes (node types, memory limits), and migration cutovers that may have shifted traffic.
- Dependencies: provider latency, error rate, timeouts; Redis latency, timeouts, hit ratio, evictions, connected clients.
- Retries: retry counters at the gateway and the funding service; inbound versus outbound request ratio.
- Logs and traces: error and timeout spikes, circuit-breaker trips, unusually large payloads, traces of slow funding calls.
3. Likely causes here
- Slow provider. Requests hang, in-flight work piles up, and each holds buffers, threads, and objects. Very common and fits a peak-hour pattern.
- Retry storm. Retries at both the gateway and the funding service multiply load (3 x 3 = up to 9x), especially without jitter or retry budgets.
- Redis degradation. Timeouts hold connections open, a fallback in-process cache grows without bound, misses push extra calls to the provider, or a large hot key is repeatedly deserialized.
- Leak from a recent deploy. Unbounded maps or local caches, unclosed connections or listeners, per-request objects never evicted.
- Organic traffic growth beyond provisioned limits.
- Migration side effects. Shadow or dual traffic from the monolith, a new caller, or a heap setting that does not match the container limit.
4. Telling the causes apart
| Hypothesis | Evidence |
|---|---|
| Deploy | Step change or new slope at deploy time; only new-version pods affected; rollback fixes it |
| Leak | Post-GC floor keeps rising; growth continues when RPS is flat; heap dump dominated by one type |
| Traffic | Memory tracks RPS; memory per request unchanged; RPS above same time last week |
| Provider | Provider p99 and timeouts rise first, then in-flight count, then memory |
| Retries | Outbound calls exceed inbound; retry counters spike; duplicate idempotency keys |
| Redis | Redis latency or evictions spike; hit ratio drops; local cache grows; provider calls rise from misses |
Two extra techniques:
- Compare pods. One bad pod suggests a hot key, stuck connection, or skewed routing. All pods bad suggests a systemic cause.
- Preserve evidence. Pull one pod out of rotation and capture a heap dump or profile before any restart.
5. Immediate mitigation
Prefer fast, reversible actions, one at a time, watching the effect.
- Roll back if a deploy or flag change correlates. Safest and fastest.
- Scale out for headroom, but beware: if the provider is the bottleneck, more pods add more concurrent load to it.
- Rolling restart to buy time on a leak, never all pods at once.
- Contain dependency slowness: tighter timeouts, circuit breakers, bulkheads or bounded queues, fewer retries or a retry budget.
- Shed non-critical load such as background refreshes or migration shadow traffic, so checkout funding is protected.
- Raise memory limits only as a stopgap, and verify heap settings match the container limit.
- Escalate to the provider if they appear degraded.
- Engage operations for fallbacks: support scripts for stuck couriers, reassigning affected orders.
6. Communication
- Declare the incident and open a dedicated channel.
- Separate roles: an incident commander coordinating, and engineers debugging.
- Post updates every 15 to 30 minutes with impact, what we know, what we are doing, and when the next update comes. Say "unknown" when it is unknown.
- Pull in the owners of the gateway, Redis/platform, the migration effort, and the provider contact. Keep support and operations informed so they can brief couriers and customers.
- Log a timeline of actions as you go; it feeds the postmortem.
7. After recovery
- Blameless postmortem with timeline, root cause, contributing factors, and what detection or response was slow.
- Resilience fixes: timeouts on every outbound call, circuit breakers, bulkheads, bounded queues, retries only at one layer with jitter and budgets, idempotency keys for funding calls.
- Memory hygiene: bound all in-process caches, set heap size relative to container limits, add leak-detection tests or soak tests.
- Redis: right-size, set eviction policy, avoid giant keys, define degraded-mode behavior when it is slow.
- Observability: alerts on leading indicators (in-flight requests, provider latency, post-GC heap floor) instead of only raw memory percent; dashboards that split canary from stable.
- Release safety: canary deploys with memory regression checks and automatic rollback.
- Capacity and load testing that include provider slowness scenarios, and a runbook for this alert.
Common mistakes
- Restarting everything immediately and destroying the evidence.
- Scaling out blindly while the provider is the bottleneck.
- Changing several things at once, so the effect cannot be attributed.
- Treating memory percent as the whole story rather than checking funding success and latency.
- Going quiet during the incident, or skipping follow-up once the graph looks normal.