Idempotent Rate-Limited Client for Writing Findings Back to an EHR
Last updated: November 29, 2026
Quick Overview
Write a client that sends accepted coding changes back to a customer's EHR API, which enforces a per-tenant rate limit and sometimes fails with retryable errors or times out after applying the change. The client must retry safely, never apply the same change twice, and respect each tenant's rate limit.
Charta Health
November 29, 20260
0
0 solved
Write a client that sends accepted coding changes back to a customer's EHR API, which enforces a per-tenant rate limit and sometimes fails with retryable errors or times out after applying the change. The client must retry safely, never apply the same change twice, and respect each tenant's rate limit.
Charta Health's value reaches the customer only when accepted findings land in the EHR or billing system, and EHR APIs are rate limited and flaky. The interviewer looks for idempotency keys, exponential backoff with jitter, a token bucket per tenant, and a clear split between retryable and permanent errors.
What the Interviewer Expects
- Derives a stable idempotency key from tenant, chart and payload
- Distinguishes retryable from permanent errors
- Uses exponential backoff with jitter and a max attempt count
- Implements a per-tenant token bucket
- Makes time and sleep injectable for tests
- Explains where the completed-key store must live in production
Key Topics to Cover
How to Approach This
- Apply SOLID principles. Single Responsibility makes code testable, Open/Closed makes it extensible.
- Choose data structures based on access patterns, not familiarity.
- Prefer immutable data and message passing over shared mutable state for concurrency.
- Design APIs with RESTful conventions, versioning, meaningful errors, and pagination from day one.
Possible Follow-up Questions
- The EHR does not support idempotency keys; how do you avoid double writes after a timeout?
- How would you make this work across many worker processes?
- How do you surface a write that permanently failed to the coder who accepted it?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice System Design ProblemsSample Answer
Requirements
send(tenant, chart_id, payload) returns the EHR response or raises. Retry on 429, 5xx and timeouts; do not retry on 4xx validation errors. A timeout may mean the write succeeded, so a retry must not...
High-Level Design
Idempotency key: a SHA-256 of tenant, chart and canonical JSON payload. It is sent with the request so the server can deduplicate, and recorded locally on success so a repeat call is a no-op. Rate lim...