PracHub
QuestionsPremiumLearningGuidesCheatsheetNEW
|Home/Other / Miscellaneous/Bloomberg

Implement RotatingFileSink in hierarchy

Last updated: Mar 29, 2026

Quick Overview

This question evaluates a candidate's proficiency in Python object-oriented design, file I/O and JSON serialization, concurrency control via locking, context manager protocols, custom exception handling, and adherence to Liskov substitution when implementing a rotating file sink.

  • Medium
  • Bloomberg
  • Other / Miscellaneous
  • Data Engineer

Implement RotatingFileSink in hierarchy

Company: Bloomberg

Role: Data Engineer

Category: Other / Miscellaneous

Difficulty: Medium

Interview Round: Technical Screen

You are given an existing Python 3.10 codebase with an abstract base class RecordSink (from abc import ABC, abstractmethod) that defines open() -> None, write(record: dict) -> None, and close() -> None. A Pipeline class instantiates a sink, calls sink.open() once, then for each record calls sink.write(record), and finally calls sink.close(); Pipeline must not be modified. Implement a new concrete RotatingFileSink that: ( 1) writes each record as a compact JSON line (UTF- 8) to disk, ( 2) rotates to a new file when either a maximum number of lines N is reached or total bytes exceed limit L, using filenames like prefix_00001.log, prefix_00002.log, etc., ( 3) supports use as a context manager via __enter__/__exit__ while preserving existing open/close semantics, ( 4) is safe for concurrent write() calls from multiple threads using a lock, ( 5) raises a custom SinkClosedError if write() is invoked after close(), and ( 6) adheres to Liskov substitution so Pipeline works unchanged. Do not alter existing method signatures or the Pipeline. Provide the full class implementation and a brief unit test showing rotation and thread-safety.

Quick Answer: This question evaluates a candidate's proficiency in Python object-oriented design, file I/O and JSON serialization, concurrency control via locking, context manager protocols, custom exception handling, and adherence to Liskov substitution when implementing a rotating file sink.

Bloomberg logo
Bloomberg
Sep 6, 2025, 12:00 AM
Data Engineer
Technical Screen
Other / Miscellaneous
4
0

You are given an existing Python 3.10 codebase with an abstract base class RecordSink (from abc import ABC, abstractmethod) that defines open() -> None, write(record: dict) -> None, and close() -> None. A Pipeline class instantiates a sink, calls sink.open() once, then for each record calls sink.write(record), and finally calls sink.close(); Pipeline must not be modified. Implement a new concrete RotatingFileSink that: (

  1. writes each record as a compact JSON line (UTF-
  2. to disk, (
  3. rotates to a new file when either a maximum number of lines N is reached or total bytes exceed limit L, using filenames like prefix_00001.log, prefix_00002.log, etc., (
  4. supports use as a context manager via enter / exit while preserving existing open/close semantics, (
  5. is safe for concurrent write() calls from multiple threads using a lock, (
  6. raises a custom SinkClosedError if write() is invoked after close(), and (
  7. adheres to Liskov substitution so Pipeline works unchanged. Do not alter existing method signatures or the Pipeline. Provide the full class implementation and a brief unit test showing rotation and thread-safety.

Comments (0)

Sign in to leave a comment

Loading comments...

Browse More Questions

More Other / Miscellaneous•More Bloomberg•More Data Engineer•Bloomberg Data Engineer•Bloomberg Other / Miscellaneous•Data Engineer Other / Miscellaneous
PracHub

Master your tech interviews with 7,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.