Skip to content
dbansal0607Public

About

Distributed Trading Benchmarking Platform

Resources

Stars

1 star

Watchers

0 watching

Forks

Latest commit

 

History

12 Commits

Folders and files

Repository files navigation

⚡ IICPC Summer Hackathon 2026

Distributed Trading Benchmarking Platform

Go Docker React TypeScript Redis InfluxDB

A production-grade distributed system that automatically evaluates contestant-submitted trading exchanges — from secure sandboxing to real-time load testing to live scoring.

Architecture Document • GitHub


🎯 What This Does

A contestant uploads their trading exchange code (C++, Rust, or Go). The platform:

  1. Sandboxes it in Docker with 6 security layers — no network, read-only filesystem, all capabilities dropped
  2. Attacks it with 500 concurrent goroutines sending 5,000 orders per second
  3. Measures every single order with nanosecond precision — p50, p90, p99 latency
  4. Scores it on a 100-point composite formula
  5. Streams live rankings to a React leaderboard via Server-Sent Events

🏗️ Architecture

[Contestant]
     |
     | POST /submit (C++/Rust/Go code)
     v
[Submission API :8080]
     |
     v
[Sandbox Runner :8085]        6 Security Layers:
     |  Docker build + run  -> NetworkMode: none
     |                      -> ReadonlyRootfs: true
     |                      -> CapDrop: ALL
     |                      -> Seccomp whitelist
     |                      -> PidsLimit: 100
     |                      -> Non-root user
     v
[Contestant Exchange :random]
     ^
     | 5,000 orders/second
     | 500 goroutines x 10 OPS
     |
[Bot Coordinator :8081]
     |
     | BotResults (batched)
     v
[Telemetry Ingester :8082]
     |  p50 / p90 / p99
     |  InfluxDB write
     v
[Scoring Engine :8083]
     |  composite score
     |  Redis ZADD
     |  SSE broadcast
     v
[React Leaderboard :3000]
     live rankings, no refresh

🚀 Quick Start

Prerequisites

  • Docker Desktop (running)
  • Go 1.22+
  • Node.js 20+

Step 1 — Start Infrastructure

docker run -d --name iicpc-redis -p 6379:6379 redis:7-alpine redis-server --appendonly yes

docker run -d --name iicpc-influxdb -p 8086:8086 \
  -e DOCKER_INFLUXDB_INIT_MODE=setup \
  -e DOCKER_INFLUXDB_INIT_USERNAME=admin \
  -e DOCKER_INFLUXDB_INIT_PASSWORD=adminpassword123 \
  -e DOCKER_INFLUXDB_INIT_ORG=iicpc \
  -e DOCKER_INFLUXDB_INIT_BUCKET=telemetry \
  -e DOCKER_INFLUXDB_INIT_ADMIN_TOKEN=iicpc-token-2026 \
  influxdb:2.7

Step 2 — Start Services (4 terminals)

# Terminal 1
cd services/scoring-engine && go run cmd/main.go

# Terminal 2
cd services/telemetry-ingester && go run cmd/main.go

# Terminal 3
cd services/bot-coordinator && go run cmd/main.go

# Terminal 4
cd services/submission-api && go run cmd/main.go

Step 3 — Start Leaderboard

cd frontend/leaderboard && npm start

Open http://localhost:3000


📊 Scoring Formula

Component Weight Metric Perfect Score
⚡ Latency 40% p99 response time < 1ms = 40 pts
📈 Throughput 35% Transactions/sec > 10k TPS = 35 pts
✅ Correctness 25% Order success rate > 99.9% = 25 pts

Why p99 and not average?

At 5,000 orders/second, a p99 latency of 500ms means 50 orders every second take half a second. In live trading, those are missed opportunities worth real money. Average latency hides this problem. p99 exposes it.

p99 < 1ms   -> 40 pts   HFT-grade
p99 < 5ms   -> 30-40    Excellent
p99 < 10ms  -> 20-30    Good
p99 < 50ms  -> 10-20    Acceptable
p99 >= 50ms -> 0 pts    Too slow

🛡️ Security Architecture

Every contestant container runs with 6 independent security layers:

Layer 1: NetworkMode: none
         -> zero network interfaces
         -> cannot access internet, other containers, or our databases

Layer 2: ReadonlyRootfs: true
         -> filesystem is read-only
         -> only 10MB writable tmpfs at /tmp

Layer 3: CapDrop: ALL
         -> all Linux capabilities dropped
         -> no raw sockets, no process tracing, no kernel modules

Layer 4: Seccomp whitelist
         -> ~200 safe syscalls allowed
         -> ptrace, kexec_load, mount blocked

Layer 5: PidsLimit: 100
         -> prevents fork bombs

Layer 6: USER contestant (UID 1000)
         -> non-root execution

Defense in depth — if one layer fails, five remain.


🤖 Bot Fleet Design

500 goroutines x 10 OPS = 5,000 total orders/second

Order mix (realistic market simulation):
  70% Limit Orders   — providing liquidity
  20% Market Orders  — taking liquidity
  10% Cancels        — position management

Each bot:
  - Independent goroutine (no shared state)
  - Own PRNG (no lock contention)
  - Persistent HTTP connection pool
  - Nanosecond timestamps on every order
  - Non-blocking result channel writes

📡 API Reference

Submission API — Port 8080

# Upload contestant code
curl -X POST http://localhost:8080/submit \
  -F "code=@exchange.cpp" \
  -F "contestant_id=alice" \
  -F "language=cpp"

# Track pipeline progress
curl http://localhost:8080/submission/abc123

# Health check
curl http://localhost:8080/health

Bot Coordinator — Port 8081

# Launch bot fleet manually
curl -X POST http://localhost:8081/start \
  -H "Content-Type: application/json" \
  -d '{
    "submission_id": "abc123",
    "target_url": "http://localhost:8000",
    "bot_count": 500,
    "orders_per_second": 10,
    "duration_seconds": 60
  }'

# Live fleet stats
curl http://localhost:8081/status

Telemetry Ingester — Port 8082

# Get p50/p90/p99 metrics
curl http://localhost:8082/metrics/abc123

Scoring Engine — Port 8083

# Score a submission
curl -X POST http://localhost:8083/score \
  -H "Content-Type: application/json" \
  -d '{
    "submission_id": "abc123",
    "contestant_id": "alice",
    "p50_ms": 0.8,
    "p90_ms": 1.5,
    "p99_ms": 3.2,
    "tps": 8500,
    "success_rate": 0.97
  }'

# View leaderboard
curl http://localhost:8083/leaderboard

🧪 Live Demo Results

Rank Contestant p99 TPS Score Grade
1 alice_hft 0.9ms 15,000 100.0 A+
2 diana_sys 2.9ms 11,000 95.0 A+
3 bob_algo 4.8ms 7,500 83.8 B
4 charlie_quant 9.2ms 3,200 63.5 C
5 eve_dev 45.0ms 800 38.0 F

⚙️ Technology Decisions

Choice Technology Why
Language Go 1.26 Goroutines for 500 concurrent bots with ~5MB total memory
Sandbox Docker CLI via exec SDK v24 has distribution package conflicts; exec gives identical functionality with zero deps
Metrics DB InfluxDB 2.7 Purpose-built time-series, native percentile queries, nanosecond precision
Leaderboard Redis Sorted Set O(log N) auto-sorted ZADD — designed exactly for rankings
Live Updates Server-Sent Events Unidirectional stream, simpler than WebSocket, proxy-friendly
Deployment Docker Compose Reproducible one-command startup, zero extra tooling

📁 Repository Structure

iicpc-platform/
├── services/
│   ├── submission-api/          # Upload + 5-stage pipeline orchestrator
│   ├── sandbox-runner/          # Docker security layer
│   ├── bot-coordinator/         # 500-goroutine load generator
│   ├── telemetry-ingester/      # Latency measurement + InfluxDB
│   └── scoring-engine/          # Composite scoring + Redis + SSE
├── frontend/
│   └── leaderboard/             # React 18 + TypeScript live dashboard
├── infra/
│   └── docker/
│       ├── docker-compose.yml   # One-command deployment (IaC)
│       ├── dockerfiles/         # C++/Rust/Go contestant templates
│       └── seccomp/default.json # Linux syscall whitelist
├── test/
│   └── mock-exchange/           # Simulated exchange for testing
└── docs/
    └── architecture.md          # Full system design document

Built for IICPC Summer Hackathon 2026 · May 9 to June 10

Distributed Systems · High-Performance Computing · Financial Technology

About

Distributed Trading Benchmarking Platform

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages