Interview conceptSystem Design

Scalable Backend Architecture And Data Modeling

Asked of: Software Engineer

Last updated

Clean architecture infographic showing client → edge → app → data layers: API gateway, LB, microservices, Kafka, Redis cache, Postgres primary+replicas, DynamoDB/Cassandra, Elasticsearch, S3; arrows for read/write and consistency notes.

What's being tested

You’re being tested on whether you can turn ambiguous product behavior into a scalable backend design with clear APIs, data models, storage choices, consistency guarantees, and operational tradeoffs. Apple interviewers care because many consumer-facing systems must be reliable, privacy-conscious, low-latency, and evolvable across huge user populations and device ecosystems. The interviewer is probing whether you can reason from requirements to architecture: what data is owned where, which reads/writes dominate, how indexes and caches work, and what breaks under concurrency or scale. Strong answers balance correctness with pragmatism: not every system needs global consensus, but you should know when eventual consistency is unacceptable.

Core knowledge

  • Requirements framing comes first: identify core entities, read/write paths, latency targets, durability needs, and consistency expectations. A good system design answer usually starts with “who calls this, how often, and what correctness guarantee do they need?” before naming databases or services.

  • Capacity estimation should drive design choices. Estimate storage as N×S×RN \times S \times R, where NN is object count, SS is average object size, and RR is replication factor. Estimate peak load using average QPS multiplied by a burst factor, often 3–10x for consumer systems.

  • Data modeling should reflect access patterns, not just normalized entities. Postgres works well for relational integrity and moderate scale; DynamoDB, Cassandra, or Bigtable-style stores fit high-write, key-value or wide-column workloads; Elasticsearch or OpenSearch fit full-text search but should not be the source of truth.

  • Primary keys affect scale and operability. Random UUIDv4 avoids coordination but hurts locality; Snowflake-style IDs encode timestamp and shard bits; database sequences are simple but can bottleneck or reveal ordering. For distributed writes, avoid hot partitions such as monotonically increasing keys without sharding.

  • Indexing is a performance contract. B-tree indexes support equality and range queries; inverted indexes power full-text search; geospatial indexes such as Geohash, S2, or R-tree support nearby queries. Every index speeds reads but increases write amplification and storage cost.

  • Caching reduces read pressure but introduces freshness and invalidation problems. Use Redis or Memcached for hot objects, query results, sessions, and rate-limit counters. Common patterns include cache-aside, write-through, and TTL-based invalidation; always specify what stale data is acceptable.

  • Replication improves availability and read scalability. Leader-follower replication gives simple write ordering but can create stale follower reads; multi-leader helps geographically distributed writes but introduces conflict resolution; quorum systems use rules like R+W>NR + W > N to improve consistency.

  • Sharding distributes data when one machine or database cluster is insufficient. Shard by stable, high-cardinality keys such as user_id, business_id, or account_id; avoid low-cardinality keys like country or status. Plan for resharding using consistent hashing or logical shard maps.

  • Consistency models should match product semantics. Reviews, ratings, and catalog metadata may tolerate eventual consistency; wallet balances, payments, and entitlement grants usually require strong consistency, idempotency, and auditable state transitions. Say explicitly where stale reads are safe and where they are not.

  • Concurrency control prevents lost updates and double execution. Use optimistic locking with a version column, compare-and-swap, database transactions, unique constraints, or idempotency keys. For financial or entitlement systems, design around append-only ledgers rather than mutable balance fields alone.

  • API design should include method semantics, authentication, authorization, pagination, idempotency, and error behavior. POST may create resources, PUT is commonly idempotent replacement, PATCH is partial update, and GET should be side-effect-free. Cursor pagination is more stable than offset pagination at scale.

  • Operational concerns are part of backend design. Mention observability with p50, p95, p99, error rate, saturation, and queue depth; safe deploys with canaries and rollback; and failure modes such as cache stampedes, hot keys, replica lag, partial writes, and regional outages.

Worked example

For Design and scale a Yelp-like platform, a strong candidate would start by clarifying scope: “Are we designing search and reviews only, or also reservations, ads, and messaging? What read/write volume should I assume? Do we need real-time review visibility?” Then they would declare a reasonable baseline: millions of businesses, hundreds of millions of reviews, read-heavy traffic, low-latency nearby search, and eventual consistency acceptable for aggregate ratings.

The answer can be organized around four pillars: data model, write path, read/search path, and scaling/operations. The data model might include User, Business, Review, Photo, and RatingAggregate, with the authoritative data stored in Postgres or a sharded relational store initially, then split by access pattern as scale grows. The write path handles creating reviews with authorization, duplicate prevention, moderation status, and asynchronous aggregate updates through a queue such as Kafka or SQS.

For reads, business detail pages can use cache-aside with Redis, while search uses a dedicated Elasticsearch index containing denormalized business fields, categories, rating summaries, and geospatial coordinates. The key tradeoff to call out is that the search index is not the source of truth: it may lag the primary database, so the UI must tolerate slightly stale rating counts or business metadata. Nearby search needs geospatial indexing, usually by bounding box plus ranking, Geohash, or S2 cells, with a final distance calculation to avoid returning incorrect edge results.

A strong close would mention abuse and operations without over-expanding: “If I had more time, I’d cover review spam defenses at the API boundary, hot-business caching during spikes, index rebuild strategy, and privacy controls around user-generated content.”

A second angle

For Migrate a monolithic wallet to microservices, the same architecture and data modeling skills apply, but the constraints become stricter. In a Yelp-like system, stale review counts are usually acceptable; in a wallet, stale balances or double debits are not. The data model should center on an append-only ledger, immutable transaction records, idempotency keys, and well-defined service ownership boundaries such as WalletService, PaymentService, and RiskService.

The migration framing should emphasize safety: strangler-fig decomposition, dual reads/writes only when carefully controlled, reconciliation jobs, and rollback paths. Instead of optimizing primarily for search latency, the key design decision is how to preserve transactional integrity across services without relying on distributed transactions everywhere. A strong answer would discuss sagas, outbox patterns, and auditability, while being clear that the ledger remains the system of record.

Common pitfalls

Pitfall: Jumping straight to microservices, Kafka, and Redis without first defining entities, traffic shape, and correctness requirements.

This sounds senior but often hides weak fundamentals. A better answer starts with the core read/write flows and introduces complexity only when a bottleneck or reliability requirement justifies it.

Pitfall: Treating every datastore as interchangeable.

Saying “use NoSQL for scale” is too vague. The interviewer wants to hear why a key-value store, relational database, search index, object store, or cache fits a specific access pattern, and what tradeoff you accept in consistency, query flexibility, or operational burden.

Pitfall: Ignoring concurrency and failure modes.

Many candidates design the happy path only: create review, update rating, return success; or debit wallet, call payment provider, update balance. Stronger answers discuss retries, duplicate requests, partial failures, idempotency keys, optimistic locking, reconciliation, and what the user sees when a dependency is degraded.

Connections

The interviewer may pivot into distributed transactions, event-driven architecture, API idempotency, geospatial search, cache invalidation, or database indexing. For senior-leaning loops, expect follow-ups on migration strategy, schema evolution, backfills, regional failover, and how to debug elevated p99 latency or inconsistent reads.

Further reading

Featured in interview prep guides

Practice questions

Related concepts