Video in progress

Staff 🌱 Spring

A big promotion is a month away and traffic is expected to be 10 times the usual. How do you prepare a system made of Spring services?

First I run a load test with a realistic scenario to find the bottlenecks and separate the critical path. Then I tune autoscaling and pools, warm the cache in advance, and put together a plan to switch off secondary features with load shedding and feature flags. A runbook is ready for the day of the promotion.

📖 Answer

I split this into a 4-week project.

Week 1: what we protect. We identify the critical path: catalog → cart → payment. Recommendations, reviews, "most viewed" are secondary. For every critical endpoint there is a target: for example, p99 < 500 ms at 3000 RPS, errors < 0.5%.

Week 2: load testing. With Gatling/k6, realistic mixed traffic (80% reads, 15% cart, 5% payment), a production-like environment and data volume. The bottlenecks that usually turn up:

  • the DB connection pool (all pods × pool size > the database's max_connections);
  • a single "hot" row (stock count): a queue of locks;
  • a slow external payment provider, which ties up Tomcat threads;
  • no cache, or a stampede onto the database when the cache goes empty.

Week 3: fixes and protection.

  • Cache data that is read a lot, and warm it before the promotion starts.
  • Handle stock with reservations (Redis atomic decrement or batched rows), not a direct UPDATE.
  • Timeouts, bulkheads and circuit breakers on external calls.
  • Load shedding: if the queue fills up, return 503 + Retry-After, which is better than choking the database.
  • Feature flags: switch off secondary features with one button.
  • "Warm up" autoscaling in advance: raise the minimum pod count before the promotion, because a JVM pod needs 30–60 seconds to start and for the JIT to warm up, so the HPA reacts too late.

Week 4: operations. Freeze: no new deploys for 3 days before the promotion. Dashboards and alerts, a runbook ("if X happens, we switch off flag Y"), an on-call team, and agreements made in advance with providers (payment provider limits, the SMS provider).

After the promotion, a postmortem, even if everything went well: which assumptions turned out right and which didn't. That is the most valuable input for next time.