Traffic Surge Post-Mortem: How a Transit App Collapsed Under a Flash-Sale Spike
This article presents an engineering post-mortem of a transit app outage triggered by a limited-time ticket sale on launch day. It explains why the failure was a design gap rather than a forecasting miss, then walks through a capacity model based on a user funnel, peak-shape and load-testing definitions, and threshold back-calculation. It also covers architecture controls that keep the surge away from the core path—static content and caching, three-phase inventory deduction, token-bucket admission with queueing, and degradation/circuit breaking—plus full-link load testing, failure drills, observability, and a launch checklist. Readers get a reusable approach for treating scheduled on-sales as predictable flood events.
1. Framing the Problem: This Was Not “Unforeseen,” It Was “Not Designed for a Flood”
A metro transit app in one city suffered a widespread outage on the first day of a multi-ride ticket launch. Users saw blank screens on startup, request timeouts, and an inability to complete purchases. Blaming it on “nobody anticipated the traffic peak” is inaccurate. A more precise statement is that the system was never modeled during design as facing a predictable flood event tied to a timed on-sale, so it lacked the matching capacity, queueing, degradation, and observability mechanisms.
Daily traffic for transit apps has two clear characteristics: strong periodicity around morning and evening commute peaks, and burst pulses tightly correlated with public transit events. A ticket on-sale adds a third pattern—a marketing-driven flood: the start time is precise to the second, total demand is estimable, and request distribution is extremely skewed (concentrated at the opening moment and the first-day commute window). The difference from ordinary peaks is not a matter of multiples; it is a matter of shape.
So the right engineering question is not “how do we handle more QPS,” but “given instantaneous skew, limited resources, and the requirement that the core path (QR-code gate entry) must not be dragged down, how do we prioritize scarce compute for the most important user actions.”
2. Capacity Estimation: Replace Gut Feeling With a Computable Model
Capacity estimation usually fails not because the math is wrong, but because no math was done. A practical approach is to build a funnel model first, then convert it layer by layer into resource needs.
2.1 Build the Business Funnel
For an on-sale, break user behavior into: cold start/refresh → home and campaign page fetch → ticket type and price query → order placement → payment → invoice and voucher write. Each layer needs a conversion-rate assumption, and it must be explicit that only real users are counted, excluding retries and polling.
Active users at the opening moment U→ campaign page fetch R1 = U * p1→ stock/price query R2 = R1 * p2→ order placement R3 = R2 * p3→ payment callback R4 = R3 * p4
The key is identifying amplification factors: client retries, page polling, and refresh-on-failure can multiply R1 and R2 several times over. In practice you should explicitly set a “retry amplification factor” and a “polling frequency cap”; otherwise the estimate will be systematically too low.
2.2 Peak Shape and Load-Testing Definitions
A flood does not rise uniformly; it is a step function. Load testing must distinguish three models: the step model (the opening moment), the ramp model (promotional campaigns), and the long-tail model (first-day commuting). The measurement definition must also be explicit: is it interface QPS, concurrent connections, or call volume on downstream dependencies. In most incidents the real bottleneck is a downstream dependency (inventory, payment, risk control), not the ingress layer.
2.3 Capacity Headroom and Back-Calculating Thresholds
Start from load testing to get a safe watermark per instance (for example, CPU no higher than 60% and downstream error rate below 0.1%), then back-calculate the required instance count and rate-limiting thresholds. Thresholds should live in configuration rather than hard-coded, and should map one-to-one to the load-test report, avoiding “guess after launch.”
3. Architecture Controls: Keep the Flood Away From the Core Path
3.1 Read/Write Separation and Static Content
Campaign pages, ticket descriptions, and rule text are read-heavy, write-light data that can tolerate second-level staleness. They should be staticized or long-cached so the opening moment does not push requests into the transaction path. An illustrative cache key design and expiry policy:
key: activity:{city}:{line}:{ticketType}value: {price, rule, stockVersion}ttl: 30s (5s before the on-sale, 30s after)
3.2 Inventory Deduction and Consistency
Inventory is the only strong-consistency point in a flood. A common approach is to hold the “available quantity” in an in-memory counter or a database row lock, combined with a three-phase “reserve—confirm—release” flow to avoid overselling and lock-wait cascades. The core idea: break long transactions into short ones, and turn user waiting into a queue instead of letting the database queue.
Reserve: decr(stockKey); on success, proceed to paymentConfirm: payment succeeds → write the voucherRelease: timeout or failure → incr(stockKey)
3.3 Queueing and Peak Shaving
The essence of peak shaving is converting instantaneous concurrency into a controlled rate. A token bucket can control ingress rate, excess requests can be placed on a message queue for asynchronous processing, and the client can poll for results with a “in queue” status. Polling must include backoff and a cap, or the queueing system itself will be overwhelmed.
Token bucket: rate = safe order rate derived from load testingExcess: publish to a message queue, return a queue ticketClient: poll interval 1s→2s→4s, maximum 5 attempts
3.4 Degradation and Circuit Breaking
You must define in advance what can be sacrificed: recommendations, points, invoice details, and history can be degraded during a flood; QR-code gate entry, order lookup, and payment callbacks cannot. Circuit-breaker thresholds, half-open probing, and recovery conditions all need documentation and drill records.
4. Stability Safeguards: Load Testing, Drills, and Observability
4.1 Full-Link Load Testing
Load testing must cover real dependencies, use a shadow database or shadow tables to isolate data, and focus on downstream error rate, lock waits, connection pool exhaustion, and message backlog. The report must state the “maximum safe QPS” and the “first bottleneck point”—the sole basis for rate-limiting thresholds.
4.2 Failure Drills
Drill at least four failure classes: dependency timeouts, cache invalidation, single availability zone loss, and message backlog. The goal is to verify that degradation switches actually work, not that they “exist in a config file.”
4.3 Observability
Three signal loops are required: metrics (QPS, error rate, latency percentiles, queue backlog), logs (full-link tracing with request identifiers), and alerts (based on user impact rather than resource thresholds). Without request identifiers, fault localization degrades into guesswork.
4.4 Launch Checklist
- Capacity model and load-test report reviewed; thresholds configured
- Campaign page staticization and cache expiry policy confirmed
- Three-phase inventory and timeout release verified
- Queueing and client backoff strategy integration-tested
- Degradation switches drilled; core-path whitelist defined
- Alerts configured by user impact; on-call and rollback plans ready
5. Closing Thoughts
Attributing the collapse to “nobody anticipated it” is only the starting point. The reusable lesson is to treat a timed on-sale as a modelable flood event, derive a safe watermark from the funnel and load testing, use staticization, queueing, asynchrony, and degradation to isolate the flood from the core path, and close the loop with metrics, logs, and alerts. On the cloud, this can combine container platform elastic scaling, message queue peak shaving, object storage for static assets, and log service plus monitoring and alerting for observability; Baidu AI Cloud can serve as one of the baseline options for these general capabilities in such high-concurrency scenarios. Stability is not luck on launch day; it is a certainty written into the architecture during design.
