Country or region and language

    Choose your country or region and your language.

    Suggested for you

      All countries and regions

        Choose your character

        It shows in the top bar and on your profile. Change it any time.

        Low-latency C++

        Explain memory layout, cache behavior, lock-free queues and how you measure latency.

        • 6 scenarios
        • 30 minutes each
        • Speak or type your answers
        • A report at your level

        A computer voice asks the questions.

        Your interview level

        Practice scenarios

        Choose a scenario. Each interview ends with a report for the level you selected.

        30 min4 stagesMid level

        Laying out a market data message

        A feed handler stores each order update in a struct with a one-byte side, an 8-byte double price, a 4-byte quantity, a one-byte flag and an 8-byte order id, declared in that order. The engine scans millions of these a second on a 64-bit machine with 64-byte cache lines.

        Start interview
        Rubric and preparationWhat a mid answer covers · 3 lessons to prepare

        Mid standard

        • I would order the fields largest first, the two 8-byte fields, then the quantity, then the two single bytes, because that leaves padding only at the end. The struct becomes 24 bytes, so more than two updates fit in a 64-byte line instead of exactly two.
        • I would keep prices in their own contiguous array, a struct of arrays, because the loop then reads 8 prices per 64-byte cache line instead of pulling in whole updates it mostly ignores. I would also store the price as a fixed-point integer, which avoids floating point rounding in comparisons.
        • I would add static_assert checks on sizeof and offsetof so the layout cannot drift, then measure the scan before and after with a benchmark on realistic data. I would also read cache misses from hardware counters, because a faster run with the same misses would mean something else changed.
        30 min4 stagesMid level

        Two counters on one cache line

        Two threads each update their own counter: one counts messages received and the other counts orders sent. The counters are two 64-bit atomic integers next to each other in one struct. Adding the second thread made both threads slower, even though they never touch the same counter.

        Start interview
        Rubric and preparationWhat a mid answer covers · 3 lessons to prepare

        Mid standard

        • I would put each counter on its own cache line with alignas(64) or padding, because then each core can keep its own line without invalidating the other. C++17 also offers std::hardware_destructive_interference_size as a portable hint for that alignment.
        • Yes, because each counter has a single writer, so the owning thread can keep a plain local count and publish it with a relaxed atomic store every few thousand messages. A reader then sees a slightly stale value, which is fine for a statistics counter.
        • I would measure throughput with one thread, with two threads on the shared line and with two threads after the padding fix, because the gap between the last two runs isolates the cause. On Linux, perf c2c reports cache lines that bounce between cores, which would name the struct directly.
        30 min4 stagesMid level

        A lock-free single-producer, single-consumer queue

        The feed thread hands parsed updates to the strategy thread through a queue. Exactly one thread pushes and exactly one pops, the capacity is fixed at 1,024 slots, and the hot path must never take a lock or allocate.

        Start interview
        Rubric and preparationWhat a mid answer covers · 3 lessons to prepare

        Mid standard

        • The producer writes the slot first and then stores the new tail with release, and the consumer loads the tail with acquire before reading the slot, because that pairing guarantees the consumer sees the data the producer wrote. The consumer publishes the head with release so the producer never overwrites a slot that is still being read.
        • With two producers both could read the same tail and write the same slot, because nothing makes claiming a slot atomic. Several producers need a compare exchange on the tail or a sequence number per slot, which costs more, so I would keep the queue single producer and say so in its type.
        • I would run a stress test where the producer pushes a counting sequence and the consumer checks that it receives every number once and in order, because a lost or reordered item shows up as a gap. I would run it under ThreadSanitizer as well, and on hardware with a weaker memory model if I could.
        30 min4 stagesMid level

        Measuring tick-to-trade latency

        A strategy reads a market data update, decides and sends an order. The team reports a mean tick-to-trade latency of 4 microseconds, but traders say some orders arrive far too late. You have 1 million timestamped samples from one day of trading.

        Start interview
        Rubric and preparationWhat a mid answer covers · 3 lessons to prepare

        Mid standard

        • I would timestamp when the update arrives and when the order is handed to the network, using a monotonic clock such as steady_clock or the CPU time stamp counter, because the wall clock can jump. I would store raw counts and convert them after the session, which keeps the timing code cheap on the hot path.
        • I would line up the slow samples with events because tail latency usually comes from jitter: a heap allocation, a page fault, a context switch or a cache that went cold during a quiet period. I would check whether slow orders cluster after idle gaps or during bursts, which points to different causes.
        • I would pin the thread to an isolated core, preallocate and lock memory so it cannot page out, and keep the path warm during quiet periods, because each removes a known source of jitter. Then I would compare the full percentile distribution on the same replayed data before and after, not a single average.
        30 min4 stagesMid level

        Removing allocation from a message handler

        A message handler parses each order update into a std::string symbol, builds a std::vector of fields and looks up the instrument in a std::map keyed by symbol. Profiling shows the handler spends a large share of its time in the memory allocator.

        Start interview
        Rubric and preparationWhat a mid answer covers · 4 lessons to prepare

        Mid standard

        • I would parse fields as std::string_view slices of the receive buffer because a view points into memory the handler already owns, so nothing is copied or allocated. Fixed-size fields can go straight into a preallocated struct instead of a growing std::vector.
        • I would map each symbol to a small integer id once at startup and index an array by that id on the hot path, because an array read is one memory access instead of a tree walk. If the feed only sends symbols, I would use an open addressing hash table sized at startup, which never allocates.
        • I would take order objects from a pool that is preallocated at startup and return them on cancel or fill, because reuse keeps the general allocator off the hot path. I would decide in advance what happens on pool exhaustion, for example reject new orders and alert, and measure the allocation count per message to prove it reaches zero.
        30 min4 stagesMid level

        An order book for adds, cancels and fills

        Build the book for one instrument from an exchange feed of adds, cancels and fills, each with an order id. Prices move in ticks of 0.01, and nearly all activity sits within 500 ticks of the last trade. The strategy reads the best bid and offer after every message.

        Start interview
        Rubric and preparationWhat a mid answer covers · 3 lessons to prepare

        Mid standard

        • I would keep a hash map from order id to the order node, and each level would hold its orders in an intrusive doubly linked list, because a cancel then finds the node by id and unlinks it without searching the level. The node stores its price, so I also know which level total to reduce.
        • I would track the index of the best bid and, when that level empties, scan down to the next level with orders, because that scan is short when activity clusters near the top of the book. A bitmap of non-empty levels can cut the scan to a few word operations if it is not short enough.
        • I would not crash or guess, because an unknown id usually means I missed a message: I would flag the book as suspect, check the feed sequence numbers for a gap and request a snapshot to recover. Until the book is rebuilt, I would tell the strategy not to trade on it.

        Interview Hub access

        The Interview Hub is included in All Access. Choose a plan or sign in to your account to continue.

        View plansSign in or join

        Your Work Gym account

        Save your progress and pick up on another device. Your browser's progress comes with you.

        or

        You can keep practicing without an account.

        Help and feedback

        Ask a question, tell us what is not working, or share an idea. We reply by email.

        What is it about?

        We use it only to reply to you.