DEV Community

Narednra Reddy Yadama
Narednra Reddy Yadama

Posted on

๐Ÿ›’ ๐——๐—ฒ๐˜€๐—ถ๐—ด๐—ป๐—ถ๐—ป๐—ด ๐— ๐˜‚๐—น๐˜๐—ถ-๐—ฅ๐—ฒ๐—ด๐—ถ๐—ผ๐—ป ๐—˜-๐—–๐—ผ๐—บ๐—บ๐—ฒ๐—ฟ๐—ฐ๐—ฒ ๐—–๐—ต๐—ฒ๐—ฐ๐—ธ๐—ผ๐˜‚๐˜ ๐—ถ๐—ป ๐—๐—ฎ๐˜ƒ๐—ฎ (๐˜๐—ต๐—ฎ๐˜ ๐—ฎ๐—ฐ๐˜๐˜‚๐—ฎ๐—น๐—น๐˜† ๐˜€๐˜‚๐—ฟ๐˜ƒ๐—ถ๐˜ƒ๐—ฒ๐˜€ ๐—•๐—น๐—ฎ๐—ฐ๐—ธ ๐—™๐—ฟ๐—ถ๐—ฑ๐—ฎ๐˜†)

Cart to cash in < 2s, across continents, with zero data loss and no double charges.
Hereโ€™s the blueprint Iโ€™d ship today ๐Ÿ‘‡

The goals

โ€ข Low latency: p95 auth + payment + inventory < 150โ€“250 ms/region

โ€ข Regulatory ready (PCI-DSS, GDPR, data residency)

๐—›๐—ถ๐—ด๐—ต-๐—น๐—ฒ๐˜ƒ๐—ฒ๐—น ๐—ฎ๐—ฟ๐—ฐ๐—ต๐—ถ๐˜๐—ฒ๐—ฐ๐˜๐˜‚๐—ฟ๐—ฒ (๐—๐—ฎ๐˜ƒ๐—ฎ + ๐—ฆ๐—ฝ๐—ฟ๐—ถ๐—ป๐—ด ๐—•๐—ผ๐—ผ๐˜)

๐—˜๐—ฑ๐—ด๐—ฒ

Global Anycast DNS โ†’ nearest region (Route53/Cloudflare)

API Gateway (Spring Cloud Gateway) + WAF + Bot detection

๐—–๐—ต๐—ฒ๐—ฐ๐—ธ๐—ผ๐˜‚๐˜ ๐—ฆ๐—ฒ๐—ฟ๐˜ƒ๐—ถ๐—ฐ๐—ฒ๐˜€ (๐—ฝ๐—ฒ๐—ฟ ๐—ฟ๐—ฒ๐—ด๐—ถ๐—ผ๐—ป)

CartService (Redis/KeyDB for hot cart state)

PricingService (Promotions, tax/VAT, shipping calculators)

InventoryService (region stock; async global reconciliation)

๐——๐—ฎ๐˜๐—ฎ & ๐—˜๐˜ƒ๐—ฒ๐—ป๐˜๐˜€

Kafka (cluster-per-region) with MirrorMaker 2 for cross-region topic replication

Postgres/Cloud Spanner/CockroachDB for orders (choose per consistency/SLA)

๐—”๐˜€๐˜†๐—ป๐—ฐ ๐—ข๐—ฟ๐—ฐ๐—ต๐—ฒ๐˜€๐˜๐—ฟ๐—ฎ๐˜๐—ถ๐—ผ๐—ป

Saga pattern implemented with Kafka Streams or Temporal (Java SDK)

The checkout flow

Create checkout session โ†’ issue checkoutId + idempotency key

Price โ†’ tax โ†’ shipping โ†’ stock reserved (short TTL)

Authorize payment (not capture yet)

Emit events: ORDER_PLACED, CAPTURED, FULFILLMENT_REQUESTED

On any failure, compensate (cancel auth, release stock, notify)

Multi-region strategies that work

Traffic & Failover

Active-active for reads, region-primary for writes per order/customer

๐—ฅ๐—ฒ๐˜€๐—ถ๐—น๐—ถ๐—ฒ๐—ป๐—ฐ๐—ฒ

โ€ข DLQs for PAYMENT_CAPTURE_FAILED / RESERVATION_EXPIRED

โ€ข Retries with exponential backoff; saga compensations always idempotent

โ€ข PSP multi-homing: Stripe + Adyen + local APMs (UPI, iDEAL, Pix)

๐—Ÿ๐—ฎ๐˜๐—ฒ๐—ป๐—ฐ๐˜† ๐—ฏ๐˜‚๐—ฑ๐—ด๐—ฒ๐˜ (๐˜๐—ฎ๐—ฟ๐—ด๐—ฒ๐˜)

Gateway + auth: 30 ms

Pricing/Tax/Shipping: 60โ€“100 ms (parallel)

End-to-end p95: < 250 ms intra-region

๐—๐—ฎ๐˜ƒ๐—ฎ ๐˜€๐˜๐—ฎ๐—ฐ๐—ธ

Spring Boot 3 + WebFlux (high-concurrency IO)

Spring Cloud (Config, Gateway, Sleuth/OTel)

Kafka + Kafka Streams / Temporal for saga orchestration

Testcontainers + WireMock for PSP & carrier mocks

๐—š๐—ผ๐˜๐—ฐ๐—ต๐—ฎ๐˜€ ๐˜†๐—ผ๐˜‚โ€™๐—น๐—น ๐—ต๐—ถ๐˜ (๐—ฎ๐—ป๐—ฑ ๐—ณ๐—ถ๐˜…๐—ฒ๐˜€)

Double charges โ†’ idempotency key stored in Redis with PSP response TTL

Stock races โ†’ reservation tokens + DB unique constraints

Global promotions โ†’ feature flags (Unleash) + time-boxed pricing snapshots

๐—ฅ๐—ผ๐—น๐—น๐—ผ๐˜‚๐˜ ๐—ฝ๐—ฎ๐˜๐—ต (๐Ÿฐ ๐˜€๐—ฝ๐—ฟ๐—ถ๐—ป๐˜๐˜€)

Single region MVP (idempotent payments + reservations + saga)

Add second region (read replica + failover drills + mirrored Kafka)

Active-active reads; PSP multi-homing; real-time analytics

Data residency & country-specific APMs; chaos tests & GameDays

If youโ€™re aiming for Black-Friday traffic without pager fatigue, this is the playbook.

Top comments (0)