PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep
|Home/System Design/Anrok

Design async batched key-value fetcher

Last updated: Apr 28, 2026

Quick Overview

This question evaluates understanding of designing asynchronous, batched request handling in a single-threaded event-loop, covering batching windows, key deduplication, response-to-callback correlation, consistency boundaries, error handling, timeouts/retries, cancellation, and backpressure.

  • hard
  • Anrok
  • System Design
  • Software Engineer

Design async batched key-value fetcher

Company: Anrok

Role: Software Engineer

Category: System Design

Difficulty: hard

Interview Round: Technical Screen

You are given a backend endpoint: HTTP GET /read?keys=k1,k2,... which returns a JSON object mapping each key to a numeric value (e.g., { "foo": 12, "bar": 100 }). You also have two primitives: ( 1) httpGetAsync(urlPath, callback) -> void, and ( 2) parseKvs(json) -> a dictionary mapping keys to values. Implement a single-threaded (event-loop) interface getKeyAsync(key, callback) that supports concurrent I/O and batches multiple incoming requests. Requirements: - Batch all requests that arrive within a 100 ms window into a single HTTP call to /read?keys=...; - Deduplicate keys within a batch; if multiple requests ask for the same key, invoke each request’s callback exactly once; - Enforce consistency: a batch response may only satisfy callbacks for requests that arrived before that batch was dispatched; requests arriving afterward must be served by a subsequent batch; - Allow multiple in-flight batches without mixing responses; - Define the data structures (queues, maps, sets), control flow (timers, scheduling), and how responses are correlated to waiting callbacks; - Specify behavior for missing keys, partial failures, timeouts/retries, and cancellation/backpressure; - Discuss complexity (time/space), single-threaded ordering pitfalls, and a brief test plan.

Quick Answer: This question evaluates understanding of designing asynchronous, batched request handling in a single-threaded event-loop, covering batching windows, key deduplication, response-to-callback correlation, consistency boundaries, error handling, timeouts/retries, cancellation, and backpressure.

Anrok logo
Anrok
Sep 6, 2025, 12:00 AM
Software Engineer
Technical Screen
System Design
10
0

Design an async, batched key-value fetcher with a 100 ms window

Context

You have a single-threaded, event-loop environment (e.g., JS/TS). A backend endpoint serves numeric values for keys via HTTP GET:

  • Endpoint: GET /read?keys=k1,k2,...
  • Response: a JSON object mapping each requested key to its numeric value, for example: { "foo": 12, "bar": 100 } .

Available primitives:

  • httpGetAsync(urlPath, callback) -> void where callback(err, jsonString) .
  • parseKvs(jsonString) -> Map<string, number> that parses the JSON string into a map of key → value.

Task

Implement a single-threaded (event-loop) interface:

  • getKeyAsync(key, callback)

that supports concurrent I/O and batches multiple incoming requests.

Requirements

  1. Batch all requests that arrive within a 100 ms window into a single HTTP call to /read?keys=... .
  2. Deduplicate keys within a batch; if multiple requests ask for the same key, invoke each request’s callback exactly once.
  3. Enforce consistency: a batch response may only satisfy callbacks for requests that arrived before that batch was dispatched. Requests arriving afterward must be served by a subsequent batch.
  4. Allow multiple in-flight batches without mixing responses.
  5. Define the data structures (queues, maps, sets), control flow (timers, scheduling), and how responses are correlated to waiting callbacks.
  6. Specify behavior for missing keys, partial failures, timeouts/retries, and cancellation/backpressure.
  7. Discuss complexity (time/space), single-threaded ordering pitfalls, and a brief test plan.

Solution

Show

Submit Your Answer to Earn 20XP

Sign in to leave a comment

Loading comments...

Browse More Questions

More System Design•More Anrok•More Software Engineer•Anrok Software Engineer•Anrok System Design•Software Engineer System Design
PracHub

Master your tech interviews with 8,000+ 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.