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.
You have a single-threaded, event-loop environment (e.g., JS/TS). A backend endpoint serves numeric values for keys via HTTP GET:
GET /read?keys=k1,k2,...
{ "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.
Implement a single-threaded (event-loop) interface:
getKeyAsync(key, callback)
that supports concurrent I/O and batches multiple incoming requests.
/read?keys=...
.
Login required