Welcome to the team that distributes market data. The service keeps the latest quote per symbol, built from a snapshot plus incremental updates, and fans quotes out to subscribers. Every update carries a monotonically in…
Welcome to the team that distributes market data. The service keeps the latest quote per symbol, built from a snapshot plus incremental updates, and fans quotes out to subscribers. Every update carries a monotonically increasing sequence number (seq) per symbol.
This repository has four reported problems, listed below as tickets. Fix as many tickets as you can in 45 minutes. Each ticket is checked separately, and you are not expected to finish every one.
You may use the AI assistant and normal repository tools. Treat the assistant like a junior developer: establish a plan, inspect its work, run the tests, and retain ownership of the result.
market_data/
models.py domain types (Quote)
store.py latest quote per symbol
sequencer.py tracks the highest seq per symbol (gap / staleness detection)
feed.py applies snapshots and incremental deltas
subscriptions.py the subscription hub (subscribe / unsubscribe / publish)
service.py MarketDataService: ties store, feed, and the hub together
tests/visible/ shipped regression tests
conftest.py puts the repository root on the import path for pytest
seq must not overwrite a newer one.Quotes occasionally flicker back to an older price. Updates can arrive out of order because of retransmits and multiple feed handlers. An update whose seq is not greater than the stored quote's seq must be ignored.
seq is not greater than the stored one is a no-op.seq still updates the quote.Do not change the subscription or feed code as part of this ticket.
After a client unsubscribes it still receives quote callbacks, and the subscription list grows without bound. Clients that come and go are slowly leaking memory and getting data they no longer want.
unsubscribe(symbol, token), publishing to that symbol does not call the removed callback.Do not change the store or the sequence logic as part of this ticket.
If one subscriber's callback raises, later subscribers for the same symbol receive nothing. A single misbehaving client is taking down fan-out for everyone on that symbol.
Do not change the store or the sequence logic as part of this ticket.
A delta for a symbol that has no prior snapshot silently fabricates a 0/0 base quote instead of failing. Downstream consumers then see a bogus zero price. A delta only makes sense on top of a snapshot.
apply_delta for a symbol with no snapshot raises LookupError.Do not change the subscription code as part of this ticket.
pytest tests/visible. Every shipped test fails on the starter code and passes once the bugs it covers are fixed.market_data/ are submitted; the shipped tests in tests/visible run as they are.MarketDataService (subscribe, unsubscribe, on_snapshot) and its store, hub and feed (QuoteStore.apply / get, SubscriptionHub.publish, MarketDataFeed.apply_delta), so keep those in place.Adapted from treasure567/bloomberg-practice (round-2/cinder @ 8de07d5), used with the author's permission.
Visible test command
pytest tests/visibleThe repository’s own tests. Run all tests includes them, and so does every submission.
Repository
market-data-stale-quotes-and-ghost-subscribers
Changes under src/ are evaluated.