Swapping Engines Mid-Flight: Engineering an HTT...

Jitin
November 20, 2026

Swapping Engines Mid-Flight: Engineering an HTTP/3 Migration on Android

HTTP3 promises faster, more resilient networking but introducing it into an existing Android application is less about flipping a switch and more about changing the engine while the plane is already flying. In this session, we'll walk through the engineering journey of migrating an existing Android networking stack from OkHttp to Cronet, enabling HTTP3/QUIC while minimizing changes to the application layer.
- Introduction to Cronet which enables HTTP3 on Android.
- Bridging Cronet to OkHttp by refactoring Interceptors, Authenticator and Cache layer, while keeping OkHttp as fallback.
- Rollout strategy of HTTP3 across all platforms (Android, iOS, Web)
- Measuring connection and request level metrics to understand improvements.

Jitin

November 20, 2026

Annual Pro sale · Save $30

Have presentations of your own?

Share with private links, password protection, and more control over your work.

Transcript

70 slides
  1. SWAPPING ENGINES MID-FLIGHT ENGINEERING AN HTTP/3 MIGRATION ON ANDROID Jitin

    Sharma Senior Software Architect, Groww jitinsharma _ @ DROIDCON INDIA · 2026 HTTP/2 HTTP/3
  2. ROADMAP Where we are going ▪ How a request travels

    ▪ Evolution of HTTP ▪ Adopting HTTP/3 on Android ▪ Migrating from OkHttp to Cronet ▪ The rollout and what we learned
  3. Sockets RawRequest.kt val socket = SSLSocketFactory.getDefault() 01 A socket is

    a two-way byte pipe .createSocket("example.com", 443) HTTP is just text in the pipe socket.getOutputStream().write( "GET /feed HTTP/1.1\r\nHost: example.com\r\n\r\n" .toByteArray() ) / / HOW A REQUEST TRAVELS 02 TCP keeps the bytes reliable and ordered 03 HTTP is text written into it
  4. HOW A REQUEST TRAVELS Connect Round trips CLIENT SERVER SYN

    TCP 1 RTT SYN-ACK ClientHello TLS 1.3 1 RTT 2 RTT with TCP + TLS 1.3 ServerHello · Finished GET /feed HTTP +1 RTT BEFORE THE FIRST REQUEST 200 OK 3 RTT with TLS 1.2
  5. EVOLUTION OF HTTP HTTP/1.1: one response at a time ONE

    CONNECTION /feed SIX CONNECTIONS /avatar ▪ One response at a time per connection ▪ Workaround: ~6 parallel connections per host /config
  6. EVOLUTION OF HTTP HTTP/2: many streams over one connection ONE

    TCP CONNECTION 1 2 3 1 2 3 1 STREAMS IN PARALLEL /feed /avatar /config TCP SEES ONE ORDERED BYTE STREAM 2 3 1 ▪ Frames from many streams, one connection ▪ HPACK header compression ▪ Catch: one lost packet stalls every stream 2
  7. EVOLUTION OF HTTP ) ( HTTP/3 HTTP/2 · TCP HTTP/3

    · QUIC TRANSPORT TRANSPORT TCP + TLS 1.3 QUIC UDP + TLS 1.3 SETUP SETUP 2 round trips 1 round trip PACKET LOSS PACKET LOSS Stalls every stream Stalls only the affected stream NETWORK CHANGE NETWORK CHANGE New connection Connection migration HEADERS HEADERS HPACK QPACK
  8. EVOLUTION OF HTTP Mobile network angle LOSSY RADIO HANDOVER HIGH

    LATENCY Packets get dropped Wi-Fi to cellular Round trips hurt Only the affected stream waits The connection survives the switch 1-RTT setup, 0-RTT on resume
  9. EVOLUTION OF HTTP HTTP/3 tradeoffs UDP CAN BE BLOCKED DISCOVERY

    COSTS A TRIP Some networks drop UDP, so clients fall back to HTTP/2 First visit usually runs over TCP, then upgrades CPU COST CONNECTION MIGRATION A user-space transport costs more CPU than TCP Transport load balancers may not support it
  10. ADOPTING HTTP/3 HTTP/3 across platforms WEB IOS ANDROID Every major

    browser, on by default ✅ URLSession, on by default since iOS 15 ✅ 🤔 SERVER SIDE QUIC on UDP 443, advertised via Alt-Svc, with HTTP/2 as fallback
  11. ANDROID NETWORKING ( Android networking options LIBRARY HTTP/2 HTTP/3 SHIPS

    AS HttpURLConnection No No OS OkHttp Yes No Library Cronet Yes Yes Play services / library HttpEngine Yes Yes OS API 34+)
  12. ANDROID NETWORKING Meet Cronet Chromium s network stack, as a

    library GOOGLE PLAY SERVICES play-services-cronet ▪ HTTP/1.1, HTTP/2, HTTP/3 EMBEDDED ▪ Battle-tested in Chrome cronet-embedded ▪ Supports request prioritization ▪ Provides network quality estimates ' Under 100 KB About 8 MB
  13. CRONET Cronet Engine Cronet.kt CronetProviderInstaller.installProvider(appContext) .addOnSuccessListener { val provider =

    CronetProvider.getAllProviders(appContext).first { it.isEnabled it.name CronetProvider.PROVIDER_NAME_FALLBACK } val engine = provider.createBuilder().build() = ! & & }
  14. CRONET Cronet UrlRequest Cronet.kt val request = engine.newUrlRequestBuilder( url, object

    : UrlRequest.Callback() { override fun onRedirectReceived(request: UrlRequest, info: UrlResponseInfo, newLocationUrl: String) {} override fun onResponseStarted(request: UrlRequest, info: UrlResponseInfo) {} override fun onReadCompleted(request: UrlRequest, info: UrlResponseInfo, byteBuffer: ByteBuffer) {} override fun onSucceeded(request: UrlRequest, info: UrlResponseInfo) {} override fun onFailed(request: UrlRequest, info: UrlResponseInfo?, error: CronetException) {} override fun onCanceled(request: UrlRequest, info: UrlResponseInfo?) {} }, executor ).build() request.start()
  15. THE MIGRATION Retrofit and OkHttp Retrofit interfaces OKHTTP API Request

    Tags Response EventListener OKHTTP CORE ENGINE Authenticator Cache CallServerInterceptor Interceptors
  16. THE MIGRATION Keep the API, swap the core Retrofit interfaces

    OkHttp API Interceptors · Tags · EventListener cronet-okhttp bridge Request/Response ↔ UrlRequest Cronet OkHttp core HTTP/3 · QUIC fallback ▪ Same Retrofit interfaces ▪ Same interceptors ▪ New engine underneath
  17. THE MIGRATION Google s cronet-okhttp bridge NetworkModule.kt val client =

    OkHttpClient.Builder() 01 Add it as the last interceptor .addInterceptor( CronetInterceptor.newBuilder(engine).build() 02 OkHttp s core is bypassed ) .build() 03 Retrofit can use CronetCallFactory github.com/google/cronet-transport-for-okhttp ' / ' / https:
  18. THE BRIDGE Authenticator Authenticator.kt class DefaultAuthenticator : Authenticator { override

    fun authenticate(route: Route?, response: Response): Request? {} } okhttpBuilder.authenticator(DefaultAuthenticator()) AuthInterceptor.kt class AuthInterceptor(private val defaultAuthenticator: DefaultAuthenticator) : Interceptor{ override fun intercept(chain: Interceptor.Chain): Response { val request = defaultAuthenticator.authenticate() chain.proceed(request) } }
  19. THE BRIDGE EventListener DefaultEventListener.kt class DefaultEventListener : EventListener() { override

    fun connectStart(call: Call, inetSocketAddress: InetSocketAddress, proxy: Proxy) {} override fun responseBodyEnd(call: Call, byteCount: Long) {} override fun callEnd(call: Call) {} override fun cacheHit(call: Call, response: Response) {} }
  20. THE BRIDGE EventListener RequestFinishedListener DefaultRequestInfoListener.kt class DefaultRequestInfoListener : RequestFinishedInfo.Listener(executor) {

    override fun onRequestFinished(requestInfo: RequestFinishedInfo) { val metrics = requestInfo.metrics connect, dns info val responseInfo = requestInfo.responseInfo } / / / / } response info
  21. THE BRIDGE Tags Tags.kt interface FeedApi { @GET("feed") fun feed(

    @Tag property: Property ): Call<Feed> } request.tag(<Clazz>)
  22. THE BRIDGE Tags <> Annotations OKHTTP OUR LIBRARY CRONET CRONET

    Request.tag(...) Forked bridge Request annotation Finished listener Tags used for metrics still reach the metrics, with no call-site changes
  23. THE BRIDGE Request Priority Priority.kt requestBuilder().setPriority() public static final int

    REQUEST_PRIORITY_IDLE = 0; public static final int REQUEST_PRIORITY_LOWEST = 1; public static final int REQUEST_PRIORITY_LOW = 2; public static final int REQUEST_PRIORITY_MEDIUM = 3; public static final int REQUEST_PRIORITY_HIGHEST = 4;
  24. THE BRIDGE Priority from a Retrofit interface RETROFIT FORKED BRIDGE

    interface FeedApi { request.tag(Priority @GET("feed") let { fun feed( @Tag priority: Priority ): Call<Feed> : : . ? } class.java) builder.setPriority(it.level) }
  25. THE BRIDGE DNS optimisations Dns.kt engineBuilder.setDnsOptions( DnsOptions.builder() .persistHostCache(true) .useBuiltInDnsResolver(true) .enableStaleDns(true)

    .setStaleDnsOptions( DnsOptions.StaleDnsOptions.builder() .allowCrossNetworkUsage(true) .setFreshLookupTimeoutMillis(0) .setMaxExpiredDelayMillis(24 * 60 * 60 * 1000) .useStaleOnNameNotResolved(false) .build() ) .build() )
  26. THE BRIDGE Caching problems: stale-if-error 1 · THE SERVER SETS

    THE BUDGET Server stale-if-error=N Cache 2 · THE API CALL FAILS Request StaleIfError Network fails on error only-if-cached Stale data
  27. THE BRIDGE Fix: OkHttp s cache in front Retrofit interfaces

    Application interceptors CacheInterceptor OkHttp: serves and stores responses cronet-okhttp bridge last interceptor Cronet ' ' ' disableCache() on every request ▪ OkHttp s cache serves and stores ▪ Cronet s cache is off per request ▪ Cronet becomes a network-only engine
  28. THE BRIDGE HttpEngine HTTPENGINE Cronet, packaged inside Android MISSING FEATURES

    RequestFinishedInfo listener Network quality estimator Request annotations API 34+ or S Extensions 7 Netlog and more
  29. THE ROLLOUT Testing the waters with images BEFORE Fresco HttpURLConnection

    fetcher AFTER Fresco OkHttp fetcher Delegating interceptor behind a feature flag Cronet OkHttp ▪ Flag picks Cronet or OkHttp ▪ Core network layer untouched ▪ No cache or authenticator to configure ▪ Play services provider: no APK growth
  30. THE ROLLOUT Pilot results CONNECTION LATENCY REQUEST LATENCY PLAY SERVICES

    BIND ~50% 25% · 10% 3s Faster Faster at p50 · p90 Bind + engine creation, p90 vs OkHttp vs OkHttp
  31. THE ROLLOUT Why the gains were capped ~10% of traffic

    fell back to HTTP/2 ▪ Some networks block UDP ▪ p50 gains look bigger than p90 ▪ One extra upgrade hop engineBuilder.addQuicHint("groww.in", 443, 443)
  32. THE ROLLOUT Core network layer DONE NEXT THEN Images POST

    APIs GET APIs Fresco pilot Controlled rollout Controlled rollout
  33. THE ROLLOUT The results flipped IMAGES (FRESCO) CORE APIS CONNECTION

    LATENCY ~50% better ~50% better REQUEST LATENCY, P90 ~10% better ~2% worse
  34. THE ROLLOUT Same engine, opposite results IMAGES PAGE APIS Large

    responses Smaller responses GET More susceptible to new connections GET and POST MEASUREMENTS TTFB End to end request latency Connection latency Error rates
  35. THE ROLLOUT Latency by network strength GOOD AVERAGE Slower HTTP/3

    vs HTTP/2 HTTP/3 pays off where the network is worst POOR Slower Faster
  36. THE ROLLOUT HTTP/3 off: Cronet vs OkHttp CONNECTION LATENCY REQUEST

    LATENCY, P90 ~30% ~14% Faster Faster vs OkHttp vs OkHttp
  37. FINAL TAKEAWAYS Where we landed CONNECTION LATENCY REQUEST LATENCY, P90

    PAGE LOAD LATENCY, P90 ~30% ~14% ~8% Faster Faster Faster vs OkHttp vs OkHttp vs OkHttp ENGINE NEXT Cronet is now our network engine, behind the same OkHttp APIs Working with Cloudflare on BBR for HTTP/3
  38. FINAL TAKEAWAYS What Cronet does differently CONNECTIONS NETWORK Connection sharing

    + coalescing Network-aware connection management IDLE SOCKETS DNS Periodic sockets probing and retry Adaptive and stale DNS
  39. FINAL TAKEAWAYS What you should try ▪ HTTP/3 is still

    worth exploring, especially on poor networks ▪ Compare results with good observability ▪ Watch for remote/edge configurations and HTTP/2 downgrades

More Decks by Jitin

Other Decks in Technology