Preparing your design workspace

Loading the problem and your saved attempt…

Design a Cross-Exchange Arbitrage Engine

Maintain valid, fresh cross-exchange quotes, emit each executable price inversion once, and track paired orders through independent execution outcomes.

Design the object model and interaction contracts for an in-memory cross-exchange arbitrage engine. Multiple exchanges publish bid and ask quotes for globally identified instruments. Each quote carries an instrument ID, exchange ID, bid price and size, ask price and size, and comparable event timestamp.

The engine maintains each exchange's current snapshot for every instrument, detects when the best bid on one exchange is greater than the best ask on another, and submits a sell to the bid exchange and a buy to the ask exchange concurrently.

For this exercise, a quote is valid only when both prices and sizes are positive and bid price is at most ask price. A slot accepts only a quote with a strictly newer timestamp; older and duplicate updates are ignored. Each instrument's feed watermark is the greatest accepted quote timestamp for that instrument.

A stored quote is fresh for opportunity detection only while its timestamp is within 500 milliseconds of that watermark, and both selected sides must be valid and fresh. Identify an opportunity deterministically from the instrument plus the bid and ask venue-and-quote-timestamp versions.

Hand a given opportunity ID to execution at most once; an update that leaves the same winning pair must not resubmit it, and another request becomes eligible only after at least one selected quote version changes.

Each leg progresses independently through submitted, accepted, partially filled, filled, rejected, or uncertain. Accepted and partially filled are nonterminal.

Filled and rejected are terminal; rejection means the venue authoritatively reports that no further fill will occur and preserves the cumulative filled quantity, which may be zero or partial.

Results carry a monotonically increasing result version and cumulative filled quantity; duplicate or older results are ignored, cumulative fill never decreases, and a timeout produces uncertain rather than rejected so a later higher-version result can resolve uncertainty into accepted, partially filled, filled, or rejected.

The two venues provide no atomic transaction. Networking, exchange authentication, hedging policy, persistence, and recovery implementation are outside scope.

Be ready to adapt the design for one million quote updates per second using preallocated contiguous storage, constant-time addressing, cache-conscious access, and incremental extrema maintenance.