System Design - Design a Real-Time Stock Trading System
[ OK ]d17ed2ef-b0b9-4a98-9657-d155f38728e6 — full content available
[ INFO ]category: System Design difficulty: unknown freq: first seen: 2026-03-13
[UNKNOWN][SYSTEM DESIGN]
$catproblem.md
This problem statement is designed to reflect the rigorous, first-principles engineering culture at xAI, where the focus often lies on ultra-low latency, extreme scalability, and mission-critical reliability.
Problem Statement: Designing a Real-Time Stock Trading System
1. Scenario
You are tasked with building the backend infrastructure for a high-frequency, real-time stock trading platform that will serve as a foundational "world model" for financial dynamics. The system must handle millions of concurrent users and process a massive volume of transactions with near-zero delay.
2. Functional Requirements
Order Execution: Users must be able to place, update, and cancel buy/sell orders (Market and Limit orders).
Matching Engine: Implement a high-performance logic to match buy and sell orders based on price and time priority.
Real-Time Feeds: Provide a live "Order Book" and price updates to all connected clients via streaming.
Risk Management: Perform "hard" risk checks (e.g., balance verification, volume limits) before any order is sent to the matching engine.
3. Non-Functional Requirements
Ultra-Low Latency: Aim for sub-millisecond round-trip latency for order execution.
High Availability: Ensure 99.99% uptime with instant fault tolerance and no single point of failure.
Strict Consistency: Financial data (balances and stock positions) must be 100% consistent; "double-spending" is not permitted.
Scalability: Support a sudden spike of up to 200,000+ orders per second during market openings.
4. xAI-Specific "Deep Dive" Constraints
First Principles Architecture: How would you build this without relying on standard, heavy-weight cloud templates? Consider bare-metal optimizations or custom networking protocols.
AI Integration: How would you integrate a real-time inference layer (like a Grok-based model) to analyze market sentiment or detect fraudulent trading patterns without adding significant latency?
Predictive Scaling: Describe a mechanism to use historical "world-state" data to preemptively scale resources before known high-volatility events.
5. Evaluation Criteria
Ability to derive architecture from first principles rather than memorized patterns.
Deep understanding of distributed systems trade-offs (e.g., Availability vs. Consistency in a financial context).
Maturity in addressing failure modes and infrastructure reliability.
Would you like to explore a specific technical solution for the order matching engine or discuss the low-latency networking requirements for this design?