Back to Blog/Backend Development
Backend Development 10 min read Published on 2025-10-28

Building Backends That Scale: What Every Mobile Developer Needs to Know

AL
Anas LakhaniMobile App Developer (Toptal Top 3%)

A beautifully designed mobile app with fluid 60fps animations will fail if the backend API takes three seconds to respond, drops requests over shaky cellular networks, or corrupts financial transactions during network handoffs.

Mobile clients operate under fundamentally different networking constraints than desktop web browsers. Phones lose reception in subway tunnels, switch cellular towers mid-request, and drop packets when waking from sleep.

Here are the critical architectural patterns every mobile developer and backend engineer must implement to build rock-solid, production-grade backends.


1. Mandatory Idempotency Keys for Mutations

On flaky mobile networks, network timeouts frequently occur after the server has already processed a request but before the client receives the 200 OK response. If a user taps "Pay $49" or "Confirm Order" and their connection blips, the mobile client will naturally retry the HTTP POST request.

Without idempotency, this results in double charges or duplicated database entries.

The Solution: - Every write mutation must include an `Idempotency-Key` UUID header generated by the mobile client. - The server records this key in Redis with a short TTL (e.g., 24 hours). - If a duplicate key arrives while processing, the server returns the cached response instead of re-executing the transaction.


2. Envelope Pagination & Cursor-Based Feeds

Never use SQL `OFFSET` pagination for mobile feeds. As users scroll down infinite feeds while new content is being continuously published, offset pagination produces duplicate items and skips records entirely.

Furthermore, `OFFSET 10000` forces the database to scan and discard 10,000 rows, destroying database CPU under high traffic.

The Solution: - Use cursor-based keyset pagination indexed by timestamp and primary ID: ```sql SELECT id, title, created_at FROM posts WHERE (created_at, id) < ($last_timestamp, $last_id) ORDER BY created_at DESC, id DESC LIMIT 20; ``` - Return pagination metadata in an envelope containing `next_cursor` and `has_more`.


3. Graceful Offline Queuing and Optimistic UI

Users should never stare at a blocking spinner while saving a favorite or updating their profile. The mobile client should immediately update local state (optimistic UI), write the operation to an on-device queue (SQLite or WatermelonDB), and synchronize with the backend when internet connectivity is re-established.

The backend must support batch synchronization endpoints (`POST /api/v1/sync`) that process operations with atomic conflict resolution rules (e.g., Last-Write-Wins or Operational Transforms).


4. Push Token Lifecycle & Silent APNs Rotation

Push notifications are critical for mobile retention and real-time VoIP alerts (as detailed in the 2nd Number VoIP case study). However, Apple APNs and Google FCM device tokens expire, rotate upon OS updates, and become invalid when apps are uninstalled.

  • Never treat push tokens as permanent database attributes.
  • Maintain a dedicated `user_devices` table with `token`, `platform`, `app_version`, and `last_active_at`.
  • Whenever APNs or FCM returns a `NotRegistered` or `DeviceTokenNotForTopic` error, immediately decommission the token to prevent wasted worker thread cycles.

Summary

Scalable mobile backends are built with defensive assumptions: connections will drop, clients will retry, and batteries must be protected. By implementing idempotency, keyset cursor pagination, and reliable token lifecycles, you ensure your platform handles hundreds of thousands of concurrent mobile users effortlessly.

Looking to architect or audit your mobile API infrastructure? Explore my Custom API & Backend Development Services.

#Backend#API Design#Node.js#PostgreSQL#System Architecture
AL

Written by Anas Lakhani

Senior Mobile App Developer with 6+ years of production experience across iOS, Android, Flutter, and React Native. Certified Toptal talent (Top 3%) who has shipped 50+ applications for startups and global enterprises.

Discuss Your Mobile Architecture

Need Help Building or Scaling Your App?

Get honest, direct architectural advice. Book a free 30-minute technical consultation with Anas Lakhani.

Book a Free Discovery Call