Design a Resilient Third-Party Token Client
Reuse valid scoped tokens and bound refresh work when a third-party token provider is unreliable.
Problem statement
For this exercise, assume service processes need opaque bearer tokens issued by a third-party provider. A token belongs to an exact credential version, audience and scope set, and has an expiry.
Independently issued tokens remain valid until expiry unless explicitly revoked; refresh does not implicitly revoke the prior token. The client never mints tokens, broadens scope or substitutes another account.
A caller supplies an authorized token tuple, a deadline and a minimum remaining validity. Return a token only when it matches that exact tuple and remains valid beyond the requested remaining lifetime plus an explicit clock-skew safety margin. Recheck validity when returning a token after waiting.
A still-valid token may be reused while refresh fails; an expired, revoked or mismatched token is never a fallback.
Design local/shared caching, early refresh, equivalent-request coalescing and bounded provider work. Network/5xx failures and429 rate limits are distinguishable from revoked credentials. Retries and concurrent refreshes have finite budgets; honor Retry-After only within the caller's deadline.
Credential rotation creates a new generation, and an old in-flight completion must not overwrite or expose tokens for the new generation. Tokens and credentials never appear in logs, metric labels or unauthorized cache reads.
A caller without a valid token receives an explicit unavailable, deadline or revoked-credential result, not fabricated success.
This practice exercise is based on an interview-preparation compilation, not an independently dated interview occurrence. The report supplies the unstable third-party token-client seed; token lifetime, tuple semantics, failure classes, security rules and the workload below are bounded practice assumptions.
Designing the provider, first-party login, user-role policy and application business requests are outside scope.
What to build
- An authorized caller obtains a token matching its credential version, audience, scope set and minimum remaining validity, or an explicit non-success result.
- The client reuses valid tokens, coalesces equivalent refresh demand and bounds retries, concurrency and provider-wide refresh rate.
- Credential rotation fences obsolete work, while operators observe cache/refresh health without exposing token or credential bytes.
At scale
- For this exercise, assume 2,000 client processes,1,000 active token tuples and20,000 application token lookups per second across the deployment.
- For this exercise, normal tokens last15 minutes and the provider-wide refresh cap is100 calls per second. Cold starts and a recovery burst may exceed that demand, so admission must remain bounded.
- For this exercise, target cached lookup p99 below 1 ms. Refresh waits obey each caller's deadline, which is at most 1 second; unavailable capacity may cause explicit rejection rather than extend the deadline.