All practice tasks

Low Level Design

Low-Level Design: Offline Sync

Replay local actions after reconnecting without skipping a failed item or losing accepted work.

Interface

Export create_offline_action_queue(). It returns a dictionary with callables enqueue(action), size(), and async drain(handler). action is a dictionary with id and optional payload. The async handler receives a before b if they were enqueued in that order.

Implement the contract in the supplied source file using Python 3. Discuss framework integration in design.md.

Behavior

  • [Q1] Process pending actions in insertion order. size counts current pending actions. An empty drain resolves without calling the handler.
  • [Q2] Raise ValueError for a missing or empty id or an id that is not a string. enqueue returns true for the first occurrence and false for any already accepted ID, including completed IDs. Instances are independent.
  • [Q3] Remove an action only after its handler succeeds. A handler exception leaves the item at the head and ends this drain without raising. A later drain retries it.
  • [Q4] Snapshot the pending list when a drain begins. Concurrent drains share the first in-flight drain and do not invoke their own handlers. Work enqueued during a drain waits f

What this task practices

Low-Level Design: Offline Sync is a low level design interview exercise that trains prompt interpretation, explicit assumptions, a concrete response, and a clear explanation of tradeoffs. The catalog marks it as easy difficulty. It focuses on Conflict Resolution, Testing, Tradeoffs. The signed-in workspace provides the tools for the round and evaluates the attempt against task-specific criteria. Reference solutions, hidden checks, evaluator instructions, and candidate work remain private.

Sign in to startThe workspace and evaluation open after sign in.