← Bloomberg Interview Insights

Bloomberg·Software Engineer·Technical Phone Screen·Senior

Senior
Jul 2026

Summary

Bloomberg data engineering interview that was basically one big coding problem: implement a production-grade rotating file sink in Python with thread safety, context manager support, and a custom exception. Pretty intense for a single question but it covers a lot of ground at once.

Questions Asked (1)

Q1

Implement a RotatingFileSink class in Python that writes records as JSON lines to disk, rotates files based on line count or byte size, supports context manager usage, is thread-safe, raises a custom error when written to after closing, and works as a drop-in replacement for an existing abstract base class without modifying the Pipeline class.

System DesignTechnical Trade-offsAPI & Integrations
Author's notes

This one took me a minute to even parse fully.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the requirements and the existing abstract base class interface, then outline the class design covering file handling, rotation logic, thread safety, and error handling. Walk through the implementation in logical chunks, explaining trade-offs and how it integrates as a drop-in replacement without modifying the Pipeline class.

Pro tip: Demonstrate awareness of production concerns like atomic file operations, log rotation edge cases (e.g., rotation during write), and performance implications of locking; mention that you'd use a lock only around critical sections to minimize contention.

1. Clarify Requirements and Interface

Ask about the abstract base class methods, expected record format, rotation thresholds, and any constraints on file naming or cleanup. Confirm that the class must be a drop-in replacement, so it must implement the same interface.

2. Design Class Structure

Outline the class with __init__ accepting file path, max lines, max bytes, and mode; include attributes for current file handle, line count, byte count, lock, and closed flag. Implement __enter__ and __exit__ for context manager support.

3. Implement Core Write and Rotation Logic

Describe the write method: serialize record to JSON, acquire lock, check if closed (raise custom error), check if rotation needed based on line count or byte size, rotate if necessary, then write and update counters.

4. Ensure Thread Safety and Error Handling

Use a threading.Lock to synchronize writes and rotations. Define a custom exception (e.g., SinkClosedError) and raise it when writing after close. Ensure close method is idempotent and releases resources.

5. Verify Integration and Edge Cases

Confirm the class inherits from the abstract base class and implements all required methods. Discuss edge cases like rotation when both thresholds are hit, handling of partial writes, and cleanup of old files if required.

Key Points to Mention

  • Inheritance from the existing abstract base class to ensure drop-in compatibility.
  • Use of threading.Lock for thread-safe writes and rotations.
  • Custom exception (e.g., SinkClosedError) raised when writing after close.
  • Context manager protocol (__enter__ and __exit__) for resource management.
  • Rotation logic based on line count and byte size, with atomic file operations.
  • JSON serialization of records as JSON lines (one JSON object per line).

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.