Originally published at Shipped Code.

Most advice on system design for mobile developers starts with "design Twitter", which does not help much with a backend for a few thousand users. At that size, the decisions that make or break the product are the API contract with the app, safe retries and offline sync, a sane relational data model, and some basic caching, background jobs and monitoring. Sharding, multi-region and microservices can wait until measured load forces them, and one well-run server with a backed-up PostgreSQL goes a long way.

As a concrete example of the shape, my own app Mockly has a Flutter client talking to a Flask backend and a MySQL database. Everything below applies to a backend like that.

TL;DR

  • Do the arithmetic first. With 100 API calls per user per day, a 10k-DAU app averages about 12 requests per second and peaks near 60.
  • Spend your design time on the API contract, idempotent writes and the data model. These are hard to change once apps are installed.
  • Use the database you already have for job queues and deduplication before adding Redis or Kafka.

What you'll learn: how to estimate load from your own numbers, which API, retry and data decisions to make before launch, and when sharding, Kafka or Kubernetes start to be worth it.

The post assumes you have shipped an app or API. Each section after the estimate summarises a topic that gets its own post later; the "what can wait" table is near the end.

Architecture of a typical small app backend

Before the details, here is the mobile app backend architecture most small products end up with, whatever the language.

Architecture of a small app product: the mobile app keeps a local database and a sync queue, sends HTTPS requests with an Idempotency-Key to one API service, which uses PostgreSQL for data and a jobs table, an optional Redis cache, and a background worker that sends push notifications and writes to object storage

The app writes to its local database first and syncs through a queue, so a flaky network does not lose user actions. One API service owns all the business logic. PostgreSQL holds the data and also the queue of background jobs. A separate worker process sends push notifications, resizes images and talks to slow third parties, so API requests stay fast. Redis is dotted because it is optional; add it when a measurement says the database is the bottleneck for a specific read.

Estimate the load before you design

The point of an estimate is to find out which order of magnitude you are in, so you stop designing for the wrong one. The numbers below are an example estimate for a 10k-DAU app, with every assumption visible. Swap in your own and rerun it.

dau = 10_000 # daily active users requests_per_user = 100 # API calls per user per day (5 sessions x 20 calls) peak_factor = 5 # busiest minute vs. the daily average rows_per_user = 10 # rows written per user per day bytes_per_row = 1_000 # row + index overhead, rough response_bytes = 5_000 # average JSON response per_day = dau * requests_per_user avg_rps = per_day / 86_400 print(f"requests/day : {per_day:,}") print(f"average req/s: {avg_rps:.1f}") print(f"peak req/s : {avg_rps * peak_factor:.0f}") print(f"DB growth/yr : {dau * rows_per_user * bytes_per_row * 365 / 1e9:.1f} GB") print(f"egress/month : {per_day * response_bytes * 30 / 1e9:.0f} GB") 
requests/day : 1,000,000 average req/s: 11.6 peak req/s : 58 DB growth/yr : 36.5 GB egress/month : 150 GB 

A million requests a day sounds like a lot until you divide by 86,400 seconds. The peak factor is the shakiest assumption here. Daily traffic curves are usually gentle, but a push notification sent to every user at once can produce a much sharper spike than 5×, so look at your own request logs once you have them.

Is 58 requests per second a lot for one PostgreSQL? You can get a rough feel with pgbench, which ships with PostgreSQL. I ran its default read/write test against postgres:17-alpine in Docker on a 10-core laptop:

pgbench -U postgres -i -s 10 postgres pgbench -U postgres -c 8 -j 4 -T 30 postgres 
number of transactions actually processed: 288669 latency average = 0.831 ms tps = 9622.001076 (without initial connection time) 

That number flatters the database. The data fits in memory, there is no network hop, and the queries are trivial. Your production box with real queries will do far less. But you could be off by a factor of 100 and still be above 58. At this scale the database rarely runs out of capacity. Slow, unindexed queries and design mistakes in the API cause the trouble instead.

Storage has the same kind of headroom: about 37 GB a year fits comfortably on one instance, and the PostgreSQL limits page puts the maximum table size at 32 TB. The egress figure is the one worth checking against your hosting plan, especially if images go through the API instead of object storage.

Design the API contract carefully from day one

Once an app version is in the stores, its API calls are frozen on every phone that does not update. You can redeploy the backend 10 times a day. You cannot redeploy the phones. That makes the contract between app and API the most expensive part of the system to get wrong. The decisions worth making on day one are these.

Pagination. Use cursor pagination (?after=<cursor>, built from a sortable key such as created_at plus id) for feeds and lists. Offset pagination shows duplicates or skips items when new rows arrive while the user scrolls, which on a phone happens all the time.

Versioning. Prefer additive changes. New fields are fine; renaming or removing a field that an old app reads is a breaking change. Have the app send its version in a header, and decide early how you will tell a too-old app to update (a minimum supported version and a force-update screen).

Errors. Return a stable, machine-readable error format, so the app can branch on a code instead of parsing a message. RFC 9457 (Problem Details) is a good default, and Spring Boot 3 supports it through ProblemDetail:

{ "type": "https://api.example.com/errors/plan-limit", "title": "Plan limit reached", "status": 403, "code": "PLAN_LIMIT" } 

The next post in this series, on API design for mobile clients, works through all 3 in detail.

Retries, idempotency and offline sync

Mobile networks drop responses, not just requests. The app sends "place order", the server saves it, the response is lost in a tunnel, and the app retries. Without protection, you now have 2 orders. So duplicates have to be handled in the API design; the client cannot prevent them.

The standard fix is an idempotency key. The app generates a UUID when the user taps the button, sends it with every retry of that action, and the server stores it with a unique constraint. There is an IETF draft for an Idempotency-Key header that describes the convention. In the database it can be as small as this (PostgreSQL 17):

CREATE TABLE orders ( id bigserial PRIMARY KEY, user_id bigint NOT NULL, idempotency_key uuid NOT NULL, total_cents int NOT NULL, UNIQUE (user_id, idempotency_key) ); INSERT INTO orders (user_id, idempotency_key, total_cents) VALUES (42, '6f1c2a9e-3b7d-4e55-9a0c-2d8f1b4e7a10', 1999) ON CONFLICT (user_id, idempotency_key) DO NOTHING RETURNING id; 

Running the same INSERT twice shows what a retry looks like:

-- first request id ---- 1 INSERT 0 1 -- retry with the same key id ---- (0 rows) INSERT 0 0 

When the insert returns no row, the API looks up the existing order by key and returns it, so the app gets the same answer both times. A real implementation also stores a hash of the request body and rejects a reused key with a different body. The unique constraint does the heavy lifting under concurrency too, since 2 simultaneous retries cannot both insert.

Offline sync is the same idea, scaled up. The app records each change in a local queue with its own UUID and replays the queue when the network returns, and the server deduplicates by that UUID. Conflicts appear when 2 devices edit the same record. For data that belongs to one user, last-write-wins is usually enough; keep a server-side version number so you can detect the rare stale write. Shared data needs a deliberate strategy. Either way, compare server versions, not device timestamps, because phone clocks drift.

If you want the deeper version, conflict strategies and idempotency keys each have a post of their own in this series.

Start with a relational data model

The database pillar and a later post on schema design for mobile backends cover this in depth; the short version is to start relational. Most app data is users, things they own, and relations between them, and a relational database enforces the rules you would otherwise have to remember in code. The idempotency example above works only because of a unique constraint. Foreign keys, NOT NULL and check constraints catch bugs from every client version at once.

A few habits pay off early. Generate IDs on the client (UUIDs) for anything created offline, so the app can reference a record before the server has seen it. Keep schema changes in versioned migrations (Flyway or Liquibase on the JVM, Alembic with Flask). Denormalise on purpose and only after measuring. A comment_count column is a fine optimisation once counting comments shows up in a slow query log, not before.

Caching, background jobs and push notifications

Cache reads that are expensive and change rarely, such as a product catalogue or app configuration. In Spring Boot, @Cacheable with an in-process Caffeine cache is often enough for a single server, and you avoid running Redis at all. Move to Redis when you run more than one API instance and need a shared cache, or when you need it for rate limiting. The hard part of caching is invalidation, so start with short TTLs on data where slightly stale is acceptable.

Anything slow or unreliable belongs outside the request. That covers emails, push, image processing and third-party calls. You do not need Kafka or RabbitMQ for a few thousand jobs a day. A jobs table in PostgreSQL with FOR UPDATE SKIP LOCKED lets several workers pull jobs without taking the same one:

SELECT id, kind FROM jobs WHERE done_at IS NULL AND failed_at IS NULL AND run_after <= now() ORDER BY run_after LIMIT 1 FOR UPDATE SKIP LOCKED; 

I tested it with 2 workers. Worker A claimed job 1 and held its transaction open for 3 seconds; worker B, starting a second later, got job 2 immediately instead of waiting:

-- worker A id | kind ----+----------- 1 | send_push -- worker B, while A still holds job 1 id | kind ----+--------------- 2 | resize_avatar 

In Spring, a @Scheduled method that runs this query, does the work and sets done_at in the same transaction is enough for a first worker.

For failures, add attempts and failed_at columns. When the work fails, catch the error, roll back the work, then increment attempts and push run_after forward in a separate transaction that commits. Once attempts reaches a limit, set failed_at instead; the failed_at IS NULL filter in the query parks the job, so it stops blocking the queue and waits for someone to look at it.

A side benefit of a jobs table is that the job is inserted in the same transaction as the business data, so you never get an order without its confirmation job. MySQL 8 supports SKIP LOCKED as well.

Push notifications are best-effort. Send them from the worker, store device tokens per user and device, and delete tokens that FCM or APNs report as invalid. Never make push the only way the app learns about a change; the app should still fetch fresh data when it opens.

If you are on the JVM, the Java backend roadmap covers where these Spring pieces fit in the bigger picture.

Observability and cost

You need to know something broke before your users email you. The minimum that covers most incidents at this scale is short:

  • structured logs with a request ID, user ID, and the app version and platform on every line, so you can see that a bug only affects app version 2.3.1 on Android;
  • metrics for request rate, error rate, p95 latency, database connections and the age of the oldest pending job;
  • alerts on 5xx rate and job queue age, sent somewhere you will actually see them;
  • backups that you have restored at least once, because you only learn whether a backup works when you restore it.

Cost follows from the estimate. The example above fits on one mid-size VPS plus either a managed PostgreSQL or a self-hosted one with automated backups. Check current prices with your provider rather than trusting a number from a blog post, and check the egress allowance in particular. Serving images straight from object storage or a CDN usually moves most of the bandwidth off the API server.

Deployment, CI and running that one server are covered in the DevOps pillar.

What can wait until later: sharding, Kafka, Kubernetes

These topics dominate system design content. Each of them solves a problem you will see in your metrics before it hurts, so you can adopt it when that happens. Use the table to decide when one starts to matter.

Topic Matters when Main trade-off
Sharding One primary cannot keep up with writes after indexing, tuning and a bigger instance Cross-shard queries and transactions get hard; every query must know the shard key
Microservices Several teams need to deploy independently Network calls replace function calls; distributed debugging and data consistency
Multi-region Users on other continents need low latency, or an outage of one region is unacceptable Data replication, conflict handling and a much bigger bill
Kafka You need durable event streams with many consumers or replay Another cluster to run; a jobs table covers simple background work
Kubernetes You run many services and need scheduling, scaling and self-healing across machines A platform to learn and operate; overkill for one or two containers

Service meshes, event sourcing and CQRS belong in the same bucket. They are useful patterns for specific problems, but you are unlikely to meet those problems at the load in the example estimate.

If I started a new backend today

The usual advice is to "design for scale" from the start. For a new product backend I would do the opposite in most places. I would start with one relational database and a monolith, on a stack like Mockly's Flask + MySQL. I would add a queue or a cache only when a measurement shows a need for it. The exception is the API contract, which I would design for old app versions from the first release, with versioning and additive changes, because that is the one decision the backend cannot fix on its own later.

Warning: The costly mistakes at this scale are rarely about load. Duplicate requests from retries, old app versions still calling endpoints you changed, and sync conflicts between 2 devices are the common ones, and each is much cheaper to design for before launch than to clean up afterwards.

In this series:

  • API design for mobile clients: pagination, versioning, errors
  • Offline sync design: conflict resolution strategies that work
  • Idempotency keys: making retries safe for payments and orders
  • System design interview resources worth paying for (and the free ones)
  • Case study: the backend behind a voice translator app

The next step is the API contract, since it is the hardest thing to change later. Published system design posts collect in the system design category.