Skip to content
derpx06.dev
WritingExplainersNotesAbout
works on my machineit's always DNSship itLGTMTODO: sleepoff by oneread the docsgit push --force-with-lease404: sleep not foundhave you tried turning it off and on againrubber duck says: explain itpremature optimisationworks on my machineit's always DNSship itLGTMTODO: sleepoff by oneread the docsgit push --force-with-lease404: sleep not foundhave you tried turning it off and on againrubber duck says: explain itpremature optimisation

Learning in public.

A student's notebook on system design, distributed systems and databases. Shared as I learn.

ReadWritingExplainersNotesAbout
ElsewhereGitHubLinkedInHugging FaceLeetCode
Say hellomanaskhairnar1511@gmail.com
derpx06
NORMALmain© 2026 Derpx06Pune, Indiatop ↑
Blog/Distributed Systems

Why mobile apps are hard: your phone is on bad internet

A phone is a copy of your data that goes offline without warning and comes back disagreeing. Most mobile bugs are exactly that.

Derpx068 Oct · 3 min read
Contents
The network vanishes and doesn't tell youOffline-first is a design, not a cacheDisagreements are a product questionThe same name tag, againWhat the reframe gets you
0% read · 3 min leftBack to top ↑
On this page0%
Contents
The network vanishes and doesn't tell youOffline-first is a design, not a cacheDisagreements are a product questionThe same name tag, againWhat the reframe gets you

Picture a salesperson using a property app in a basement showroom with no signal. They update three deals, add a note, and put the phone away. Ninety minutes later the app reconnects. Its changes must now be matched with a server that has accepted changes from two colleagues and an overnight import.

That's not really a mobile problem. It's the problem of keeping several copies of the same data in agreement when they can't always talk. Think of a group project where everyone edits their own copy of a file. That is a distributed system: many machines that have to act like one. The only unusual part is that one copy lives in a pocket.

The network vanishes and doesn't tell you

Phone networks are not always fast or reliable. Worse, they often fail without any warning.

Signal bars say yes
Real speed is near zero
Reply never arrives
App frozen for four minutes, login expired
Four ways 'connected' lies.

Wi-Fi can show full bars while nothing loads. Public Wi-Fi can answer every request with a login page, so code expecting data gets HTML (a web page) instead. Each of these turns into the report "sometimes it doesn't save," which nobody can repeat on office Wi-Fi. The system isn't broken. It works as designed, in a place its design didn't expect.

Connected is not a yes-or-no question

The only real proof that something saved is a reply you received and checked. A connection indicator is a guess about the near future.

Offline-first is a design, not a cache

A cache keeps the last answer so the screen has something to show when the network is down, but saving still assumes the server is reachable. Offline-first means the phone's copy is the truth for the screen, and talking to the server is a background chore that catches up later.

  1. The phone names things itself. Make a unique ID on the device at creation, so a note on a brand new contact can be written down offline.
  2. Every record has a status. Waiting, sending, saved or failed, so the screen can say "safe on this phone, not yet on the server."
  3. The waiting list survives being killed. The OS will stop your app mid-sync, so keep pending changes in durable storage (storage that survives the app closing), saved in the same step as the data.

Disagreements are a product question

Two people edited the same deal, and one was offline. Engineers often list the options: last one wins, merge, keep both, server decides. Starting from that list is the mistake. Start from what a person expects, field by field.

FieldWhat to doWhy
StageMost recent deliberate change winsA stale update must not undo progress
NotesKeep both, appendLast one wins would destroy a note
OwnerStop and ask a personNo algorithm can settle who owns it
If you decide by time, use a clock you trust

Phone clocks are wrong, sometimes by hours. Stamp the time when the server receives the change, not when the phone sent it.

The same name tag, again

The OS, the network layer and your own queue all retry, so the server getting the same change more than once is just routine. It's like sending a message, seeing no confirmation, and sending it again. If creating a deal isn't safe to repeat, that basement showroom produces three deals.

1Phone makes an ID per change
2Server saves ID with result
3Same ID again
4Server returns the first result
Repeats become harmless.

The device-made ID from earlier does double duty here, which is a nice bonus of good design.

What the reframe gets you

Once the phone is just another copy of the data, bug reports stop being a random pile.

ReportReal problem
Sometimes it doesn't saveDurable queue
It saved and then went backDisagreement
It made twoRepeat delivery
It showed me old dataCache

The network isn't going to get better. Your model of what you're building can.

Key takeaways
  • A phone is just another copy of your data that can't always reach the others.
  • Treat the phone copy as the truth for the screen, and sync in the background.
  • Make IDs on the device, give each record a status, and keep the waiting list in durable storage.
  • Settle disagreements field by field, and make repeats safe with a unique ID.
ShareXLinkedInEmail
Written by Derpx06A developer who builds AI search tools and the code around them. I explain what I got wrong first, so you can skip it. Spotted a mistake? Tell me — corrections get credited.
Distributed Systems · 6 minHow does your computer know the time? (And why it can be wrong)Distributed Systems · 4 minWhat are CRDTs? How shared documents stay in syncDistributed Systems · 4 minHow does TCP work on bad Wi-Fi?
Start here
01Why is 0.1 + 0.2 not 0.3 in code?02How does Git work inside? (Snapshots, not changes)03How does your computer know the time? (And why it can be wrong)