Skip to main content

Parallel Aggregator

Challenge on lesson: Checkpoint: Async & HTTP

Build Solution: - interface Shard { int fetch(String key); } — a data shard. - static int totalFromAll(List<Shard> shards, String key) — call every shard (sequentially is fine), treating a shard that throws RuntimeException as contributing 0 (fault isolation). - static CompletableFuture<Integer> asyncTotal(List<Shard> shards, String key) — same semantics via completedFuture/thenApply chains with one exceptionally per shard, joined with allOf + sum. Failures in one shard must not poison the others — that's the contract.

Difficulty: intermediate

Back to lesson: Checkpoint: Async & HTTP