System Design: Crypto Trading via Third‑Party Exchanges
Context
You are designing a trading service that accepts client orders (e.g., market and limit) and routes them to third‑party cryptocurrency exchanges. Third‑party exchanges expose nominally synchronous REST/RPC APIs, but may be slow or unreliable. The service must reliably track order state, handle partial fills, and scale under spiky traffic.
Assume:
-
Users trade using balances held in your system; you must reserve funds before routing orders.
-
Multiple exchanges may be integrated; each has different authentication, rate limits, and semantics.
-
The client expects a quick acknowledgement and eventual, accurate execution status.
Tasks
-
Propose a high‑level architecture that integrates with multiple third‑party exchanges exposing synchronous APIs, while providing a responsive interface to clients.
-
Define the life‑cycle and state transitions of an order (including partial fills, cancels, and failure/unknown states).
-
Explain how to handle third‑party exchange timeouts, retries, and failures (including idempotency and reconciliation).
-
Describe strategies to cope with spiky traffic loads while respecting third‑party rate limits and preserving system stability.