Design an asynchronous logger with formatting

Quick Overview

This question evaluates expertise in concurrent programming, lock-free MPMC queue usage, producer–consumer asynchronous logging, variadic formatting APIs, and robustness in shutdown/flush semantics and error handling.

Design an asynchronous logger with formatting

Company: Qube Research & Technologies

Role: Software Engineer

Category: System Design

Difficulty: hard

Interview Round: Technical Screen

Design and implement an asynchronous C++ logger that accepts variadic arguments with fmt-style format strings, uses a background thread to perform formatting and writing, and passes messages via a provided lock-free queue. Assume we do not optimize for heap usage or memory footprint. Specify the public API, the log event structure, the producer–consumer flow, and demonstrate shutdown/flush behavior and error handling.

Quick Answer: This question evaluates expertise in concurrent programming, lock-free MPMC queue usage, producer–consumer asynchronous logging, variadic formatting APIs, and robustness in shutdown/flush semantics and error handling.

|Home/System Design/Qube Research & Technologies
Qube Research & Technologies logo
Qube Research & Technologies
Sep 6, 2025, 12:00 AM
hardSoftware EngineerTechnical ScreenSystem Design
10
0

Design an Asynchronous C++ Logger Using a Lock-Free Queue

Context

You are asked to design and implement an asynchronous logger suitable for a technical screen in a systems/engineering interview. The logger must:

  • Accept variadic arguments using fmt-style format strings.
  • Use a background thread to perform formatting and writing.
  • Pass log events through a provided lock-free queue.
  • Not optimize for heap usage or memory footprint (allocations are acceptable).

Assume a generic lock-free MPMC queue is provided with a minimal try_enqueue/try_dequeue API. You should:

  • Specify the public API.
  • Define the log event structure.
  • Describe the producer–consumer flow.
  • Demonstrate shutdown/flush behavior.
  • Describe error handling and overflow policy.

Requirements

  1. Public API that supports:
    • Variadic, fmt-style logging (compile-time format checking preferred).
    • Flush and shutdown semantics.
    • Configurable sink (e.g., file or stderr) and error handling hooks.
  2. Log events must be enqueued by producers and formatted/written by a background consumer thread.
  3. Messages should be passed as events through the lock-free queue; formatting happens only on the consumer side.
  4. Show robust shutdown/flush that drains the queue and avoids message loss.
  5. Explain error handling (enqueue overflow, formatting errors, I/O failures).

Submit Your Answer to Earn 20XP

Sign in to leave a comment

Loading comments...