Practice assignment
Resilient HTTP client take-home assignment
- Timeouts
- Retries
- Fallback
- Circuit breaker (TS)
- 3–4 hours
A currency converter depends on a flaky third-party rates provider. It must stay useful when the provider is slow or down, and it must not invent a rate for an unknown currency. The Spring Boot task focuses on timeout, three attempts, and a last-good-rate fallback per pair. The TypeScript task also requires a circuit breaker, single-flight, and a max staleness.
The starter
GET /api/convert?from=EUR&to=USD&amount=10
→ {amount, rate, stale}
upstream GET {base}/rates/{from}/{to} → {"rate": 1.08}
Work in RatesClient.rate (Java) or in ratesClient, circuitBreaker and ratesService (TypeScript). Tests use a local fake upstream and, on the Node task, an injected clock.
Requirements
- A timeout on each attempt. The TypeScript brief requires the timeout to cover the response body, not only the connect.
- Up to 3 attempts on 5xx and timeouts. Never retry 4xx (not only 404).
- Upstream 404 →
400 UNKNOWN_CURRENCY. A cached rate must not hide that, and a cache entry for one pair must not be used for another. - If every attempt fails, return the last good rate for that pair with
stale: true, or503 RATES_UNAVAILABLEif there is none. - Converted amount: 2 decimals,
HALF_EVENon the Java task.
Grading rubric
| Area | Points |
|---|---|
| Correctness (provided tests) | 30 |
| Retry / timeout policy correct, no retry on 4xx | 20 |
| Fallback & error mapping (and circuit breaker on the Node task) | 15 |
| Own tests (backoff, fake upstream, no sleeps) | 15 |
| Observability: logs or metrics on retries | 5–10 |
| NOTES.md: jitter, Retry-After, shared breaker state, libraries | 10–15 |
Levels: junior ≥ 60, mid ≥ 75, senior ≥ 85 (and a strong NOTES.md).
What reviewers look for
- A single place that decides “is this retryable?”.
- Fallback keyed by currency pair, with a story about staleness.
- On the Node task: one half-open trial, and single-flight so a stampede does not open the breaker.
- NOTES.md that mentions jitter, an overall deadline, and when to use Resilience4j, cockatiel or opossum instead of a hand-rolled loop.
Common mistakes
- Retrying 404s, then falling back to a stale EUR/USD rate for an unknown currency.
- A tight retry loop with no timeout on the body.
- A process-global “last rate we saw”, not per pair.
- Flaky tests that
Thread.sleepand hope the backoff has finished. - Opening a circuit and then allowing a herd of half-open calls.
How to run it
Java: mvn verify. Node.js: npm ci and npm test (the fake upstream binds to 127.0.0.1, no internet needed).
Paste a job ad that mentions retries, resilience or third-party APIs, and generate a practice task.
Generate one from a job adRelated practice tasks
Frequently asked questions
- Do I have to use Resilience4j?
- No. A clear, tested hand-rolled policy is enough for the timebox. Saying in NOTES.md when you would switch to a library is part of a senior submission.
- Is a circuit breaker required on the Java task?
- It is not in the Java brief. Adding a simple one can help if the tests still pass; on the TypeScript task it is required.
- Why not retry every failure?
- A 4xx will fail the same way on the next attempt. Retrying it hides bugs (a 404 becomes 'unavailable') and can amplify load.
Practice only. This is an original HireCheck practice assignment, not a real employer's take-home, and it is not affiliated with any company mentioned as a role example.