Home/Interview questions/Low-Latency C++ for Trading
Interview prep · 11 IT courses · 98 questions

9 C++ Low-Latency interview questions and answers

Questions that come up in technical interviews, with model answers. Try answering out loud first, then open the question to compare.

Q01What is RAII?C++Basic

Resource Acquisition Is Initialisation: a resource such as memory, a file or a lock is acquired in a constructor and released in the destructor.

Because destructors run when scope ends, even during an exception, resources cannot leak. std::unique_ptr and std::lock_guard are standard examples.

Q02Why is std::vector usually faster than std::list?ContainersBasic

A vector stores elements contiguously, so the CPU prefetches them and cache hits are high.

A list allocates every node separately and walking it means chasing pointers, which causes cache misses. For most sizes a vector wins even for inserts in the middle.

Q03What are move semantics?C++Intermediate

Moving transfers resources from an object that is about to be discarded instead of copying them. std::move casts a value to an rvalue so the move constructor is chosen.

Mark move constructors noexcept, otherwise std::vector copies instead of moving when it reallocates.

Q04What is false sharing?ConcurrencyIntermediate

Two threads write to different variables that sit on the same cache line. The line bounces between cores and both threads slow down even though they share no data.

Fix it by aligning or padding hot variables to separate cache lines, typically 64 bytes, for example with alignas(64).

Q05Why avoid heap allocation on the hot path?PerformanceIntermediate

malloc and new can take locks, touch new pages and cause page faults, so their latency is unpredictable.

Pre-allocate at start-up and use object pools or arena allocators so the hot path never calls the general-purpose allocator.

Q06How do you measure latency correctly?MeasurementIntermediate

Report percentiles such as p50, p99 and p99.9, not the mean, and store results in a histogram.

Warm up first, pin threads to cores, use a steady clock or the TSC, and avoid coordinated omission, where a slow response delays the next measurement and hides the worst cases.

Q07Explain memory_order_acquire and memory_order_release.ConcurrencyAdvanced

A release store guarantees that all writes before it are visible to any thread that reads that value with an acquire load.

This is how a producer publishes data in a queue: write the slot, then release-store the new tail. The consumer acquire-loads the tail before reading the slot. It is cheaper than sequential consistency on many CPUs.

Q08How would you design a single-producer, single-consumer lock-free queue?DesignAdvanced

Use a fixed-size ring buffer with a power-of-two capacity so indexes wrap with a bit mask. Only the producer writes the tail and only the consumer writes the head, both as atomics using release on store and acquire on load.

Put head and tail on separate cache lines. The queue is full when tail − head equals capacity and empty when they are equal.

Q09What data structures would you use for a limit order book?TradingAdvanced

Keep bids and asks as price levels. Near the spread, an array indexed by price tick gives O(1) access, while a sorted map works for sparse prices.

Each level holds a FIFO queue of orders for price-time priority, and a hash map from order ID to order gives O(1) cancels and amends.

LATENCY

These topics are taught in full in Low-Latency C++ for Trading, a live cohort starting soon (date to be announced) · ₹50,000.

View course

Get new batch dates first

One email when a cohort opens, plus free interview questions. No spam.

Chat on WhatsApp