Back to all projects

Polymarket Clone

Event-Driven Prediction Markets Exchange

A high-performance, event-driven prediction markets exchange built with a microservices architecture, replicating the core trading infrastructure of platforms like Polymarket for order placement and real-time feed updates at scale.

Repository

Polymarket Clone replicates the core trading infrastructure of a prediction markets exchange, focused on order placement, matching, and real-time feed distribution across decoupled services.

  • Prediction market exchanges need to process order placement and matching with low latency while staying resilient under bursty trading volume.
  • Keeping a real-time orderbook and price feed consistent across services without tight coupling is difficult.
  • Change data needs to propagate to downstream consumers reliably without polling the primary database.

Decoupled Rust services exchange events over NATS/Redpanda, with Debezium streaming PostgreSQL changes downstream and Redis caching hot market data for low-latency reads.

System Architecture DiagramClick to expand
Polymarket Clone Architecture Diagram
Data Flow

Client places an order via the REST API.

Order service validates and persists the order to PostgreSQL.

Debezium captures the change and publishes it to Redpanda.

Matching engine consumes the event stream and updates the orderbook.

Market data is cached in Redis and pushed to clients over WebSocket.

Key Architectural Decisions

  • ✓Built a microservices architecture in Rust with dedicated services for orders, matching, and market data, communicating over NATS and Redpanda.
  • ✓Used Debezium for change-data-capture out of PostgreSQL, streaming updates to Redis and connected clients over WebSocket.
  • ✓Containerized every service with Docker and Docker Compose for local orchestration and reproducible environments.
AxumRustPostgreSQLRedisNATSRedpandaDockerDocker ComposeWebSocketDebeziumNext.jsTypeScriptTailwind CSS
  • Change-data-capture with Debezium removes the need for services to poll the database, keeping the system loosely coupled.
  • Rust's performance and safety guarantees are well suited to a matching engine that must stay correct under concurrent load.