All posts

Senior Backend Interview: Architecture — Monoliths, Message Queues and Caching

When a monolith, when microservices, sync vs async, message queue semantics and caching strategies — no hype and no dogma.

Marijan Kopčić••2 min read
Senior Backend Interview: Architecture — Monoliths, Message Queues and Caching

Architecture questions are a test of maturity. They don't expect you to know every pattern, but to know when a given problem actually exists.

Monolith vs microservices

A monolith is one deploy and one database — simpler until the team and the system have grown. Microservices give you independent scaling and deploys, but you pay with the network, with observability, and with consistency becoming your problem. I wouldn't split until it hurts.

Synchronous vs asynchronous

Synchronously, the user waits for the response. Asynchronously, the work goes onto a queue and the user gets a confirmation right away. I push onto the queue everything that doesn't have to happen before the response — emails, reports, syncs with external systems.

Message queue semantics

  • At-most-once — a message can be lost.
  • At-least-once — a message can be repeated, so jobs must be idempotent.
  • Exactly-once is hard in practice and usually comes down to at-least-once plus deduplication by key.

Caching strategies

Most often cache-aside: check the cache, if it's not there read from the database and store it. The key question is invalidation — I clear on an event, not on hope. On top of that, a TTL as a safety net in case something slips through.

$post = Cache::remember("post:{$slug}", 3600, fn () => Post::where('slug', $slug)->firstOrFail());

How to prevent duplicate processing

An idempotency key — the client sends a unique key, the server remembers it and the second time returns the same result instead of creating a new record. With money and reservations it isn't optional, it is a must.

Keep reading