System Design
HTTP Client Library
hardPremiumAsked at
By Rotem Meidan ·
"Design an HTTP client library like OkHttp."
Analyzing the Problem
OkHttp behind Retrofit is an HTTP client library for Android: one shared client runs requests synchronously or asynchronously with plug-ins for cross-cutting concerns like auth and logging, reuses warm connections per host with many in-flight requests over a single connection via HTTP/2 multiplexing, caches responses on disk keyed by URL plus Vary headers, pins each host to its server certificate with a backup pin for safe rotation, retries only failures that are safe to replay spaced out so a recovering server isn't stampeded, and cancels or caps the total time of any single call. Past the socket, the server on the far side is someone else's problem.