Enterprise-Scale 100k+ TPS Order Processing System Architecture

CK CK 3788 
Created at  
179 0 0

This architecture is designed to handle ultra-high concurrency (100,000+ Transactions Per Second) during peak events (e.g., flash sales, limited-edition drops) while ensuring zero data loss, strict transactional integrity, and sub-second response times.

 

1. High-Level Architecture Overview

To process 100k+ TPS without overloading the persistent storage layer, the architecture decouples synchronous user interactions from asynchronous database writes.

Enterprise-Scale 100k+ TPS Order Processing System Architecture

 

 

2. Ingestion & Buffering Layer (Throughput Distribution)

Directly hitting a Relational Database Management System (RDBMS) with 100k TPS will cause instant lock contention and system failure. This layer absorbs sudden traffic spikes and levels the load.

Enterprise-Scale 100k+ TPS Order Processing System Architecture

API Gateway & Rate Limiting

  • Edge Protection: Deploy an API Gateway (e.g., Kong, AWS API Gateway) to filter out duplicate requests, perform token bucket rate limiting, and block malicious bot traffic.
  • Decoupled Order Intake: The Order Edge Service acts as a lightweight ingestion engine. Its sole responsibility is validation, checking/deducting memory-based inventory, publishing an "Order Created" event, and returning a 202 Accepted status to the client.

 

Message Queue Buffering (Apache Kafka)

  • Asynchronous Processing: Instead of synchronously waiting for database writes, order requests are serialized into event payloads and pushed to Kafka.
  • Partitioning Strategy: Kafka topics are partitioned using a consistent hashing key (e.g., user_id or order_id). This guarantees:
    • Horizontal scalability by distributing partitions across multiple brokers.
    • In-order processing of messages for any single user.
  • Backpressure Control: Consumers pull messages from Kafka in batches (e.g., 500 records per batch). If the downstream database slows down, consumers naturally throttle their ingestion rate, protecting the DB from crashes.

 

 

3. High-Speed Concurrency & Inventory Control

Preventing "overselling" (double-spending of inventory) at 100k TPS requires extremely fast, atomic operations before the data ever reaches the physical database.

Enterprise-Scale 100k+ TPS Order Processing System Architecture

 

In-Memory Inventory Reservation (Redis Cluster)

  • Why Redis?: Single-threaded execution of commands ensures absolute serializability of operations at sub-millisecond latencies.

 

Optimization: Lua Scripting vs. Distributed Locks

  • The Problem with Distributed Locks (Redisson): Acquiring, holding, and releasing locks across network boundaries introduces latency and overhead that degrades performance at 100k TPS.
  • The Solution (Lua Scripts): Rather than locking, run atomic Lua scripts directly inside Redis. Because Redis executes scripts atomically, the check-and-deduct sequence happens in a single step without thread context switching.
-- Atomic Inventory Deduction Lua Script
local inventoryKey = KEYS[1]
local requestedQuantity = tonumber(ARGV[1])

local currentStock = tonumber(redis.call('get', inventoryKey) or "0")

if currentStock >= requestedQuantity then
    redis.call('decrby', inventoryKey, requestedQuantity)
    return 1 -- Success
else
    return 0 -- Insufficient Stock
end

 

Read-Through Cache & Reconciliation

  • Redis as Source of Truth for Stock: During peak sales, Redis acts as the temporary source of truth for stock levels.
  • Reconciliation: The asynchronous consumer updates the persistent database. If a database transaction fails (e.g., due to payment failure), a compensating event is published to return the stock back to Redis.

 

 

4. Database Scale-Out & Data Integrity

To handle 100k writes per second, the storage layer must scale horizontally, and reads must be separated from write operations.

Enterprise-Scale 100k+ TPS Order Processing System Architecture

Database Sharding (Horizontal Partitioning)

  • Sharding Key: Shard the relational database (e.g., PostgreSQL or MySQL) using user_id (or tenant_id for B2B) as the shard key.
  • Uniform Distribution: Consistent hashing ensures that write operations are evenly distributed across $N$ database instances (e.g., 10 shards handling 10k TPS each, which is well within RDBMS limits).
  • Local Transactions: Keeping all data related to a single user's order within the same physical shard avoids slow, complex distributed transactions (2PC - Two-Phase Commit).

CQRS (Command Query Responsibility Segregation)

  • Write Store (Command): Relational databases optimized for rapid single-row inserts (INSERT INTO orders ...). These databases do not handle complex search queries or read operations.
  • Read Store (Query): Read-optimized data stores (e.g., Elasticsearch for order history search, Redis for order status caching).
  • Data Sync (CDC): Use Change Data Capture (CDC) tools like Debezium to read transaction logs from the Sharded DB in real-time and stream updates to the Read Store via Kafka. This ensures low-latency eventual consistency without impacting write performance.

 

Enterprise-Scale 100k+ TPS Order Processing System Architecture

 

 

5. Transactional Integrity & Resilience

Operating asynchronously requires robust patterns to ensure data consistency across distributed systems.

Enterprise-Scale 100k+ TPS Order Processing System Architecture

Transactional Outbox Pattern

  • To prevent inconsistency where an order is saved in the database but the event fail to publish to Kafka:

1. The Order Service writes both the Order record and an OutboxEvent record to the sharded database within the same local RDBMS transaction.
2. A CDC engine (Debezium) polls the Outbox table and safely publishes the events to Kafka.
3. This guarantees At-Least-Once delivery of events.

 

Saga Pattern for Distributed Transactions

  • When an order spans multiple microservices (Order, Payment, Inventory, Shipping):
    • Use a Choreography-based Saga Pattern managed via Kafka events.
    • If the Payment Service fails, it emits a PaymentFailed event.
    • The Inventory Service listens to this event and executes a compensating transaction to restore stock in both Redis and the RDBMS.

 

Graceful Degradation & Failover

  • Circuit Breakers: Implement Resilience4j on API calls to third-party payment gateways. If latency spikes, fail fast and queue the request for retry.
  • Polite Notification: If the consumer lag on Kafka increases, the UI transitions to a polling state, notifying users: "Your order is in queue. We will notify you via push notification shortly." This maintains a seamless user experience under extreme loads.
Tags Apache Kafka CQRS Architecture Database Sharding Distributed Transactions High Concurrency Order Processing Outbox Pattern Redis Cluster Saga Pattern System Architecture TPS 쇼핑몰 Facebook X
Comments 0
Similar posts
  1. Architecting Dynamic Scale-Out and Scale-In with Docker Containers
    134
  2. Enterprise-Scale 100k+ TPS Order Tracking System Architecture
    204
  3. Real-Time Inventory & WMS System Design
    244
  4. Designing Resilient Infrastructure to Prevent Order Data Loss During Kafka Failures
    156
  5. Architecture Design - Database Partitioning vs. Sharding
    153
  6. Stateful Databases: A Deep Dive with Cassandra & TiDB
    189
  7. Multi-AZ Kafka Architecture
    148
  8. System Design: High-Traffic Time-Deal Promotion System
    175
  9. Cadence Programming Model - A Distributed, Fault-Tolerant, Stateful Workflow Orchestration Framework
    294
  10. Optimize the performance of a search results page that experiences high traffic
    143
  11. Temporal Programming Model - Robust, Long-Running, Fault-Tolerant Applications as WorkFlows
    358
  12. Apache Kafka Explained: Powering Netflix, Building with PHP
    492
  13. Java Kafka on CentOS 7: Install, Configure, & Run with Examples
    425
  14. Scaling Sharded Databases: Taming Hot Shards with Dynamic Rebalancing
    550
  15. Improving nested_fields data access experience with a persistent user-defined function (aka UDF) in Google Big Query
    1,500
  16. Creating a serverless Apache Kafka publisher using AWS Lambda
    563
  17. Apache Kafka - a distributed, fault-tolerant, high-throughput streaming platform
    615
  18. Real-time Data Streaming Solutions - Kafka vs. Kinesis Comparison
    853
  19. Architectural Diagram Gallery for Amazon MSK
    502
  20. Arm Kernel DNNs: Powering Efficient AI at the Edge
    225
  21. The Blueprint of Success: Why System Design and Architecture Matter?
    401
  22. Bridging the Gap: How Machine Learning Integrates with Infrastructure
    277
  23. System Requirements and Architecture: Intelligent Priority-Based Scheduler
    167
  24. Beyond Static Pipelines: Architecting LLM Multi-Agent Systems for Autonomous Workflow Orchestration
    583
  25. Designing a Skill Registry Architecture: Minimize Token Usage and Maximize AI Performance
    231
  26. The Two Clocks of Ad Server Architecture
    70
  1. Software Design Patterns Cheat Sheet
    3,323
  2. Various naming for the Software Architecture - I can't find Component-based Architecture, Functional Architecture
    3,334
  3. Builder Pattern - offering pre-defined Interfaces to set Individual Parts
    1,432
  4. Abstract Factory Pattern - Commonly Used for UI Themes or Objects
    1,469
  5. Software Design Patterns
    1,437
  6. Observer Pattern
    2,395
  7. Factory Method Pattern allows overriding to return different concrete object types
    1,528
  8. How to Design Redis Caching in Infrastructure Architecture
    158
Recently updated
  1. Why 100% SEO Guarantees Better User Engagement and How to Achieve It in Your Service
    42
  2. Why SPF and DKIM Are Essential for Linux Email Servers?
    36
  3. How do I create animated background for Google Meet?
    20,994
  4. MaxMind GeoLite2 vs. DB-IP Lite vs. ip-api.com: Choosing the Right Free IP Geolocation Solution
    251
  5. Meet Valkey: Why Redis Changed Its License, Why Valkey is Better, and How to Use It as a Drop-in Replacement
    94
  6. How Rogue Web Scrapers Are Stealing My Content and Destroying My Server
    157
  7. Array of arguments passed to script in PHP
    90
  8. Invalid Auction Storms in Ad Tech
    98
  9. Building MRC-Compliant Instrumentation in Ad Tech: Implementation Steps and Key Challenges
    202
  10. Frequency Cap Architecture Overview
    515
  11. Collecting Proof-of-Play from 100,000 Screens
    146
  12. Vector Search in Relational Databases (RDBs): Trends & Usage Environments
    288
  13. What is RedisVL?
    109
  14. TPU & GPU Cluster Management Tools
    245
  15. The Concept of Scaffolding in AI Agents
    234
  16. AI-DLC vs. AI-SDLC: Model-Centric vs. System-Centric AI Development
    259
  17. Fine-Tuning Open-Weight LLMs: Training, Licensing, and Deploying Custom Models with Ollama
    339
  18. Inside the Next-Generation Streaming Architecture: Ultra-Low Latency, SGAI, and AI Codecs
    202
  19. Machine Learning: Training vs. Ranking
    222
  20. The Continuous Learning Machine: Designing a Loop That Actually Turns
    222
  21. The Next-Gen Low-Latency Standards: LL-HLS & MoQ
    195
  22. Designing a Data Curation System Around a Vector Database
    221
  23. Extracting Context from Live Video: The Architecture Got Simpler When We Stopped Building Features
    256
  24. The New Ad Stack Behind Live Sports Streaming: Inside SGAI, EABN, and the Standards Race to Fix Live Monetization
    656
  25. Designing MLOps Architectures to Handle Seasonal Data Drift in EV Fleet Models
    196
  26. From 15 to 40+ FPS: Accelerating PyTorch Object Detection on Automotive ECUs
    219
  27. Understanding Data Lineage
    262
  28. GPU & LLM Cluster Infrastructure & Task Scheduling Architecture
    245
  29. Java Variant Type
    202
  30. When Do You Need Real-Time Model Registry Versioning Powered by Autonomous Agents?
    230