On a laptop with fibre, the network feels reliable. On a phone, it isn't. People walk into lifts, switch between Wi-Fi and 4G, and background your app mid-request.
If your app assumes every request succeeds exactly once, you will eventually create duplicate orders, lose form data or show endless spinners. This post covers three patterns that fix most of these problems.
1. Retry with exponential backoff and jitter
Retrying immediately makes a struggling network worse. Wait longer after each failure, and add randomness so thousands of clients don't retry in sync.
const sleep = ( ms : number ) => new Promise (( r ) => setTimeout ( r , ms ));
export async function withRetry < T > ( fn : () => Promise < T > , { retries = 4 , baseMs = 400 , maxMs = 8000 } = {} ): Promise < T > { let attempt = 0 ; while ( true ) { try { return await fn (); } catch ( err : any ) { const retryable = err . name === " TypeError " /* network failure */ || ( err . status >= 500 && err . status < 600 ) || err .…