Skip to content
System Design

Software Architecture interview questions and answers

85 questions, 15 with code. About 5 h 14 min to read them all.

By TestLab · Updated

Plan for an interview
85 questions

Track what you know and what to revise.

Sign in to track progress

You can open a few full answers without signing in. Sign in to read all

1

What is the difference between software architecture and software design?

Software architecture is the set of high-level, hard-to-change decisions about a system: its major components, how they communicate, where data lives, and which quality attributes (scalability, availability, security) it optimizes for. Software design is the lower-level, more local work inside those boundaries: classes, functions, data structures and algorithms within a component. Architecture decides what the parts are and how they fit; design decides how each part is built.

Read full answer

Applies togeneral software engineering practice

Comparison

Aspect Software architecture Software design
Scope Whole system or several systems One component, module or feature
Typical decisions Monolith vs services, sync vs async, database choice, deployment model Class structure, patterns, interfaces, algorithms
Driven by Quality attributes and business constraints Functional requirements and code quality
Cost of change High: affects many teams and components Lower: usually local to a module
Typical artifacts C4 context and container diagrams, ADRs, deployment views Class and sequence diagrams, API signatures, code
Who owns it Architects and senior engineers across teams Developers within a team

A Useful Rule of Thumb

Architecture is “the decisions you wish you could get right early, because they are expensive to change later” (a paraphrase of ideas from Martin Fowler and Ralph Johnson). Whether a decision is architectural depends on its cost of change, not on its size.

Example: An Online Food-Ordering App

Architectural decisions

  • Start as a modular monolith with separate modules for ordering, payments and delivery tracking.

  • Use PostgreSQL for orders and Redis for live courier locations.

  • Send order events to a message queue so notifications and analytics are asynchronous.

  • Target 99.9% availability and p99 checkout latency under 500 ms.

Design decisions

  • The ordering module uses a PricingStrategy interface for different discount rules.

  • Order is an aggregate that validates its own state transitions.

  • Retry logic uses exponential backoff in a small helper class.

How They Relate

  • Architecture constrains design: if the architecture says “modules talk only through published interfaces”, designs must respect it.

  • Design feeds back into architecture: repeated design problems (for example a module that every feature changes) may signal a wrong architectural boundary.

  • The line is a spectrum, not a wall; senior engineers move between both levels.

Common Mistakes

  • Treating architecture as only diagrams; it is the decisions and their rationale, which is why ADRs matter.

  • Making architectural choices implicitly in code (for example a shared database between modules) without recording or discussing them.

  • Over-designing early: choosing microservices before the domain and team size justify it.

Interview Tip

Give a crisp definition, then use cost of change and scope as the dividing lines, with one concrete example of each. Interviewers often follow up with “give me an architectural decision you made and the trade-off involved”.

2

What is separation of concerns in software architecture?

Separation of concerns (SoC) is the principle of dividing a system into parts so that each part handles one distinct responsibility (a “concern”) and knows as little as possible about the others. Examples are separating the user interface from business rules, business rules from data storage, and core logic from cross-cutting concerns such as logging and security. It makes systems easier to understand, change, test and scale.

Read full answer

Applies togeneral software architecture principle (term popularized by Edsger Dijkstra, 1974)

What Counts as a Concern

  • Presentation: how data is shown and input is collected.

  • Business logic: rules, calculations, workflows.

  • Data access: storing and retrieving data.

  • Integration: talking to payment gateways, email providers, other services.

  • Cross-cutting concerns: logging, authentication, caching, monitoring, error handling.

Where SoC Appears in Architecture

Level How concerns are separated
Layered architecture Presentation, application, domain and infrastructure layers
Hexagonal / clean architecture Domain core isolated from adapters (web, database, messaging)
MVC / MVVM Model, view and controller (or view model)
Modules / bounded contexts Billing, catalog, shipping as separate modules or services
Middleware and aspects Logging, auth and rate limiting applied outside business code
Infrastructure Configuration and deployment separated from application code

Example

In an e-commerce checkout without SoC, one controller method validates the cart, calculates tax, writes SQL, calls the payment API and formats HTML. A change to tax rules risks breaking payment code.

With SoC:

  1. Controller handles the HTTP request and response.

  2. Checkout service applies business rules (stock, tax, discounts).

  3. Order repository saves the order.

  4. Payment adapter talks to the payment provider.

  5. Middleware handles authentication and logging.

A tax change now touches only the checkout service, and the payment provider can be swapped by replacing one adapter.

Benefits

  • Maintainability: changes are localized to the part responsible.

  • Testability: business rules can be unit-tested without a database or web server.

  • Reusability: the same domain logic serves a web app, a mobile API and a batch job.

  • Parallel work: teams own separate concerns with fewer conflicts.

  • Replaceability: swap a database, UI framework or vendor with limited impact.

Trade-offs

  • More indirection: more files, interfaces and layers to navigate.

  • Over-separation: splitting a simple CRUD app into many layers adds ceremony without benefit.

  • Wrong boundaries: separating by technical layer when features cut across them can make every change touch every layer. Feature-based (vertical) slicing is sometimes better.

Related Principles

SoC is closely linked to high cohesion and low coupling, the Single Responsibility Principle (SoC applied at class level) and information hiding (David Parnas).

Interview Tip

Define it, give a layered or hexagonal example, and mention the cost of over-separation. A common mistake is equating SoC only with “three layers”; it applies at every level, from functions to services.

3

What are quality attributes in software architecture and why do they matter?

A quality attribute is a measurable property of a system that describes how well it performs its functions, rather than what functions it performs. Examples are performance, scalability, availability, security, maintainability and testability. Quality attributes matter because they drive most architectural decisions: many architectures can deliver the same features, but they differ in how fast, reliable, secure and changeable the system is.

Read full answer

Applies togeneral software architecture practice (ISO/IEC 25010 quality model; SEI quality-attribute scenarios)

Common Quality Attributes

Attribute Question it answers Example measure
Performance How fast does it respond? p99 latency < 300 ms
Scalability Can it handle growth? 10x users with linear cost
Availability Is it up when needed? 99.95% monthly uptime (about 22 minutes downtime)
Reliability Does it behave correctly over time? Error rate < 0.1%
Security Is it protected against misuse? No critical vulnerabilities; MFA for admins
Maintainability How easy is it to change? A typical feature ships in days, not weeks
Testability How easy is it to verify? 80% of logic covered by fast automated tests
Deployability How easily can it be released? Multiple safe deploys per day
Observability Can we see what is happening? Traces for 100% of failed requests
Usability How easy is it to use? Task completion rate

Why They Matter

  • They shape the architecture: a system that needs 99.99% availability needs redundancy across zones; a system that needs strict consistency avoids eventually consistent replication for core data.

  • They conflict: more security (encryption, extra checks) can cost performance; more flexibility can cost simplicity. Architecture is largely about choosing these trade-offs deliberately.

  • They are expensive to add later: retrofitting scalability or security into a finished system often means redesign.

  • They make requirements testable: “fast” is vague; “p95 under 200 ms at 2,000 requests per second” can be tested.

Writing Them as Scenarios

The SEI approach describes each attribute as a scenario with a source, stimulus, environment, artifact, response and response measure:

“When 5,000 users submit orders per minute during a sale (stimulus, environment), the checkout service (artifact) processes them (response) with p99 latency under 500 ms and no lost orders (measure).”

Example Trade-off

A payment service prioritizes consistency, security and auditability over raw throughput, so it uses ACID transactions and synchronous validation. A product-recommendation service prioritizes availability and latency, so it serves cached, slightly stale results when its model service is slow.

Best Practices

  • Identify the top three to five attributes with stakeholders; not everything can be top priority.

  • Quantify each one and turn it into tests or monitoring (load tests, SLOs, security scans).

  • Record trade-offs in architecture decision records.

  • Revisit them as the business changes; a startup’s priorities differ from a regulated enterprise’s.

Interview Tip

Name a few attributes, explain that they conflict, and give a concrete trade-off. A common mistake is listing attributes without measurable targets; interviewers look for numbers.

4

What is a software architectural pattern?

A software architectural pattern is a proven, reusable solution to a recurring problem in a system’s overall structure: it names a set of component types, their responsibilities, and the rules for how they interact. Examples include layered architecture, client-server, event-driven, microservices, hexagonal (ports and adapters), pipe and filter and MVC. Each pattern brings known strengths and known costs for quality attributes.

Read full answer

Applies togeneral software architecture practice

Architectural Pattern vs Design Pattern

Aspect Architectural pattern Design pattern
Scope Whole system or major subsystem Classes and objects inside a component
Examples Layered, microservices, event-driven Strategy, Observer, Factory, Adapter
Decides Major components and their communication How a specific piece of code is structured
Cost of change High Low to medium

Common Architectural Patterns

Pattern Core idea Good for Watch out for
Layered Presentation, business, data layers; each uses the one below Typical business apps Changes cutting through every layer
Client-server Clients request services from a central server Web and mobile apps Server as bottleneck
Modular monolith One deployable with strongly separated modules Most new products Discipline to keep module boundaries
Microservices Independently deployable services per business capability Large teams, independent scaling Distributed-systems complexity
Event-driven Components react to published events Decoupled, asynchronous workflows Harder tracing, eventual consistency
Hexagonal / clean Domain core with ports; adapters for I/O Testable, long-lived domains Extra indirection
Pipe and filter Data flows through independent processing steps ETL, compilers, media processing Overhead between stages
Serverless Functions run on events, managed by a provider Spiky, event-based workloads Cold starts, vendor lock-in
Peer-to-peer Nodes act as both client and server File sharing, blockchains Coordination, trust

Why Patterns Are Useful

  • Shared vocabulary: saying “event-driven with a modular monolith” communicates a lot instantly.

  • Known trade-offs: you inherit experience about what each pattern does to performance, scalability and maintainability.

  • Faster decisions: start from a pattern and adapt it instead of inventing structure from scratch.

  • Combination: real systems mix patterns, for example a layered modular monolith that publishes events to a pipe-and-filter analytics pipeline.

Choosing a Pattern

  1. Identify the most important quality attributes (scalability, time to market, consistency).

  2. Consider team size and skills; microservices without operational maturity usually hurt.

  3. Consider domain complexity and how often parts change independently.

  4. Start with the simplest pattern that meets the goals, and design it so you can evolve (for example a modular monolith that can split later).

  5. Record the choice and its trade-offs in an ADR.

Common Mistakes

  • Pattern-first thinking: choosing microservices because they are popular, not because the problem needs them.

  • Mixing patterns without clear boundaries, ending up with a “distributed monolith”.

  • Treating a pattern as a rigid template instead of a starting point.

Interview Tip

Define the term, separate it from design patterns, and compare two or three patterns with when to use and when not to use each. Interviewers look for trade-off reasoning, not a ranking.

5

What is the layered architecture pattern?

The layered architecture pattern (n-tier) organizes a system into horizontal layers, each with one kind of responsibility, where each layer uses only the layer directly below it (or the layers below). The classic layers are presentation, application/business, persistence and database. It is the most common starting structure for business applications because it is simple and separates concerns clearly.

Read full answer

Applies togeneral software architecture practice

Typical Layers

Layer Responsibility Example contents
Presentation User interface and API endpoints Controllers, views, request/response models
Application / service Use cases and workflow coordination PlaceOrderService, transactions
Domain / business Business rules and entities Order, PricingPolicy
Persistence / infrastructure Data access and external systems Repositories, ORM mappings, API clients
Database Storage PostgreSQL, MySQL

Request flow: Client → Controller → Service → Domain → Repository → Database, and the response returns the same way.

Closed vs Open Layers

  • Closed layer: a request must pass through it; the presentation layer cannot skip the service layer to reach the repository. This keeps dependencies predictable.

  • Open layer: may be skipped, for example a shared utilities layer. Too many open layers erode the structure.

Benefits

  • Separation of concerns: UI, rules and data access are independent.

  • Easy to understand: most developers know the pattern.

  • Testability: business layers can be tested with fake repositories.

  • Replaceability: change the UI framework or database with limited impact on business rules.

  • Team organization: specialists can work on different layers.

Drawbacks

  • Changes cut across layers: adding one field to a form often touches the view, DTO, service, entity, repository and migration.

  • Sinkhole anti-pattern: requests pass through layers that add no logic, just forwarding calls.

  • Database-centric design: business logic tends to depend on the persistence layer, making it hard to test and change. Hexagonal or clean architecture invert this dependency.

  • Monolithic deployment: all layers usually deploy together, so it does not help independent scaling of features.

  • Performance overhead from many mapping steps (entity to DTO to view model).

When to Use It

  • Typical business and CRUD applications, internal tools and early-stage products.

  • Teams new to the domain who need a simple, familiar structure.

  • As the internal structure of each module in a modular monolith or each microservice.

When Not to Use It

  • Systems where features change independently and fast; consider vertical slices or modules per feature.

  • Domains with rich business rules that must stay independent of infrastructure; consider hexagonal / clean architecture.

  • High-scale systems with very different scaling needs per feature.

Example Improvement

A common evolution is layers inside modules: split the application by business capability (orders, billing, catalog), and use layers inside each module. That keeps the simplicity of layers while limiting cross-feature coupling.

Interview Tip

Explain closed layers and the sinkhole anti-pattern, and compare layered with hexagonal architecture (dependencies pointing toward the domain). A common mistake is calling it “MVC”; MVC is a presentation pattern that can live inside the top layer.

6

What makes a good software architecture?

A good software architecture meets its most important quality attributes (such as availability, performance and maintainability) with the simplest structure that works, has clear boundaries between parts (high cohesion, low coupling), makes change cheap where change is likely, and is understood and followed by the team. Its key elements are well-defined components and interfaces, deliberate trade-offs, documented decisions and the ability to evolve.

Read full answer

Applies togeneral software architecture practice

Elements of a Good Architecture

  • Driven by quality attributes: decisions trace back to measurable goals, such as “99.9% availability” or “a new payment method in under two weeks”.

  • Clear components and responsibilities: each module or service has one purpose and owns its data.

  • Well-defined interfaces: components interact through explicit, stable contracts (APIs, events), never through each other’s internals or shared tables.

  • High cohesion, low coupling: related logic lives together; changes in one part rarely force changes elsewhere.

  • Separation of concerns: business rules are independent of UI, frameworks and infrastructure.

  • Simplicity: no more moving parts than needed; complexity must justify itself.

  • Designed for failure: timeouts, retries, redundancy and graceful degradation where availability matters.

  • Security by design: least privilege, encryption, validated inputs and audited access built in.

  • Observability: logs, metrics and traces that let you understand behaviour in production.

  • Testability and deployability: automated tests and safe, frequent releases.

  • Evolvability: easy to extend and refactor; reversible decisions made quickly, irreversible ones carefully.

  • Documented decisions: ADRs and C4 diagrams explain why, not just what.

Signs of a Good vs Poor Architecture

Sign Good architecture Poor architecture
Adding a feature Touches one or two modules Touches many modules and teams
Failures Contained, degrade gracefully Cascade across the system
Onboarding New developers productive in days Months to understand dependencies
Testing Fast unit tests for business rules Only slow end-to-end tests
Deployment Frequent, low-risk Rare, risky “big bang” releases
Decisions Recorded with rationale Known only to a few people

Example

A ticket-booking platform:

  • Modular monolith with modules for events, bookings, payments and notifications, each owning its tables.

  • Synchronous API for seat selection (needs immediate consistency), asynchronous events for confirmations and analytics.

  • Redis cache for event listings with a short TTL; seat inventory always read from the database.

  • ADR explaining why a modular monolith was chosen over microservices for a team of eight.

  • SLOs: 99.9% availability, p99 booking latency under 800 ms, monitored with alerts.

Common Mistakes

  • Over-engineering: microservices, event sourcing and Kubernetes for a small product with one team.

  • Under-engineering: no module boundaries, so the code becomes a “big ball of mud”.

  • Ignoring non-functional requirements until production problems appear.

  • Architecture only on paper: diagrams that do not match the code.

Interview Tip

There is no universally “good” architecture, only one that fits its goals and constraints. Say that first, then list the elements and give one trade-off you would make. Interviewers value “simplest thing that meets the quality attributes” over buzzwords.

7

What is modularity in software architecture?

Modularity is the degree to which a system is divided into separate modules, each with a clear responsibility, a well-defined interface and hidden internals, so modules can be understood, changed, tested and replaced independently. A modular system has high cohesion inside each module and low coupling between modules.

Read full answer

Applies togeneral software architecture principle (rooted in David Parnas's 1972 paper on information hiding)

What Makes a Good Module

  • Single, cohesive purpose: for example “billing” or “inventory”, not “utilities”.

  • Explicit public interface: other modules call only its published API or consume its events.

  • Hidden implementation: internal classes, tables and algorithms can change without affecting others (information hiding).

  • Owns its data: no other module reads or writes its tables directly.

  • Minimal dependencies, ideally in one direction with no cycles.

Levels of Modularity

Level Example
Code Functions, classes, packages
Language modules Java modules (JPMS), .NET assemblies, Go packages, Python packages
Application modules Modules in a modular monolith (orders, payments, catalog)
Services Microservices, each independently deployable
Platform Separate data stores, infrastructure components

Benefits

  • Easier to understand: developers can work on one module without knowing all of them.

  • Parallel development: teams own modules with fewer merge conflicts and coordination meetings.

  • Testability: modules can be tested in isolation with fakes for their dependencies.

  • Replaceability and reuse: swap a payment provider module or reuse a notification module.

  • Change containment: a change in pricing logic stays inside the pricing module.

  • Evolution path: a well-modularized monolith can later extract modules into services if scaling or team size requires it.

Example: Modular Monolith

An e-commerce app is one deployable with modules:

  • catalog exposes ProductQuery; owns the products tables.

  • orders exposes PlaceOrder; publishes an OrderPlaced event.

  • payments subscribes to OrderPlaced; owns payment records.

Rules are enforced in code: module internals are package-private, and an architecture test (for example ArchUnit in Java) fails the build if orders imports payments internals.

Measuring Modularity

  • Change coupling: how often files in different modules change together (from version-control history).

  • Dependency graphs: count of dependencies and cycles between modules.

  • Instability and abstractness metrics (Robert C. Martin) for package design.

Trade-offs

  • Upfront thinking: finding good boundaries needs domain knowledge; wrong boundaries are costly.

  • Indirection: interfaces and events add some complexity.

  • Too fine-grained modules create coordination overhead without benefit.

Common Mistakes

  • Modules that share a database schema, which couples them through data.

  • A “common” or “shared” module that grows into a dumping ground everything depends on.

  • Splitting by technical layer only (controllers, services, repositories), so every feature touches every module.

Interview Tip

Connect modularity to information hiding, cohesion and coupling, and mention the modular monolith as a practical way to get its benefits without distributed-systems costs.

8

What are coupling and cohesion in software architecture?

Cohesion measures how closely the responsibilities inside one module belong together; coupling measures how much one module depends on other modules. Good architecture aims for high cohesion and low coupling: each module does one well-defined job, and modules interact through small, stable interfaces, so a change in one rarely forces changes in others.

Read full answer

Applies togeneral software design and architecture principles (Larry Constantine and Edward Yourdon, structured design)

Cohesion

High cohesion means everything in a module serves the same purpose.

  • High: an invoicing module that creates invoices, calculates tax and generates PDFs for invoices.

  • Low: a utils module with date formatting, email sending and currency conversion.

Classic cohesion types, from weakest to strongest: coincidental, logical, temporal, procedural, communicational, sequential, functional (the best: one well-defined task).

Coupling

Low coupling means modules know little about each other.

Coupling type Example Strength
Content Module A changes B’s internal data Worst
Common / shared data Modules share global state or the same database tables Very strong
Control A passes flags telling B what to do internally Strong
Stamp A passes a large structure B only partly uses Medium
Data A passes only the simple data B needs Weak (good)
Message / event A publishes an event; B reacts Weakest

Architecture-level coupling also includes temporal coupling (both services must be up at the same time for a synchronous call), deployment coupling (must release together) and semantic coupling (both depend on the same hidden business assumption).

Why They Matter

  • Change cost: with low coupling, a change in pricing logic does not ripple into checkout, shipping and reporting.

  • Understandability: a cohesive module can be understood on its own.

  • Testability: low-coupled modules can be tested with simple fakes.

  • Team autonomy: teams can own modules and release independently.

  • Failure isolation: loosely coupled services fail without taking others down.

Example

Before: the orders service reads the payments database directly to check payment status. Any schema change in payments breaks orders (high coupling), and the orders code mixes order logic with payment queries (low cohesion).

After: payments publishes PaymentCaptured events, and orders updates its own status when it receives one. Each service owns its data and logic (high cohesion), and the only shared contract is the event schema (low coupling).

How to Achieve It

  • Draw module boundaries around business capabilities (bounded contexts), not technical layers.

  • Hide internals; expose small, stable interfaces.

  • Prefer events or well-defined APIs over shared databases.

  • Apply dependency inversion: depend on abstractions owned by the consumer.

  • Watch change coupling in version control: files that always change together probably belong together.

Trade-offs

Zero coupling is impossible: modules that work together must share something. The goal is coupling that is explicit, minimal and stable. Over-decoupling (events for everything) can make flows hard to follow and debug.

Interview Tip

Define both, give one concrete before-and-after example, and mention architecture-level coupling types (temporal, deployment, shared database). A common mistake is thinking microservices automatically give low coupling; a shared database or chatty synchronous calls create a distributed monolith.

9

What is the Law of Demeter in software architecture?

The Law of Demeter (LoD), or principle of least knowledge, says a unit of code should talk only to its immediate collaborators and not reach through them into other objects’ internals: “talk to friends, not strangers”. In practice, a method should call methods only on itself, its parameters, objects it creates, and its own fields, avoiding chains such as order.getCustomer().getAddress().getCity().

Read full answer

Applies togeneral object-oriented design and architecture principle (proposed at Northeastern University, 1987)

The Rule

A method m of object O may call methods of:

  1. O itself

  2. m‘s parameters

  3. objects created inside m

  4. O‘s direct fields (components)

It should not call methods on objects returned by those calls (“strangers”).

Why It Matters

Each extra dot in a chain like a.b().c().d() is a dependency on the internal structure of another object. If Customer stops holding an Address directly, every caller that navigates through it breaks. LoD reduces this structural coupling, so internals can change without rippling outwards.

Example

from dataclasses import dataclass


@dataclass
class Address:
    city: str
    pin: str


@dataclass
class Customer:
    name: str
    _address: Address

    def shipping_city(self) -> str:          # expose what callers need
        return self._address.city


@dataclass
class Order:
    order_id: str
    _customer: Customer

    def shipping_city(self) -> str:
        return self._customer.shipping_city()


def delivery_zone(order: Order) -> str:
    # Violation would be: order._customer._address.city
    city = order.shipping_city()             # talk only to the direct collaborator
    return "metro" if city in {"Mumbai", "Delhi", "Bengaluru"} else "regional"


order = Order("o-1", Customer("Asha", Address("Pune", "411001")))
print(delivery_zone(order))                  # regional

At the Architecture Level

  • Services should call the service that owns the data through its API, not query another service’s database or the services behind it.

  • API gateways and facades give clients one entry point instead of knowledge of every internal service.

  • Modules expose a small public interface; other modules must not import their internal packages.

  • Events let consumers react without knowing who else participates.

Benefits

  • Lower coupling and easier refactoring.

  • Clearer responsibilities: the object that owns the data provides the behaviour (Tell, Don’t Ask).

  • Easier testing: fewer nested objects to fake.

Trade-offs and Misreadings

  • Wrapper explosion: forwarding methods for every nested property makes classes bloated. Add only methods with real meaning (shipping_city, not get_address_pin_last_digit).

  • Fluent APIs and data structures are fine: query.where(...).order_by(...) returns builders of the same abstraction, and plain data transfer objects (DTOs) or JSON documents are meant to be navigated.

  • It is a guideline, not a dot-counting rule.

Interview Tip

Explain it as reducing knowledge of other objects’ structure, show a train-wreck chain and its fix, and mention the service-level version (no reaching into another service’s data). A common mistake is applying it to fluent builders or DTOs, where chaining is intended.

10

How are cross-cutting concerns handled in software architecture?

Cross-cutting concerns are behaviours needed across many parts of a system, such as logging, security, error handling, caching, transactions, monitoring and validation, that do not belong to any single business module. They are handled by centralizing them outside business code: in middleware, filters and interceptors, aspect-oriented programming (AOP), decorators, shared libraries, or at the platform level in API gateways and service meshes.

Read full answer

Applies togeneral software architecture practice (examples: ASP.NET Core middleware, Spring AOP, Express middleware, Envoy/Istio)

Common Cross-Cutting Concerns

Concern Typical central mechanism
Authentication and authorization Middleware, gateway, policy annotations
Logging and tracing Middleware, interceptors, OpenTelemetry instrumentation
Error handling Global exception handler
Validation Request filters, schema validation
Caching Decorators, HTTP cache layers, CDN
Transactions Declarative annotations (@Transactional), unit-of-work middleware
Rate limiting API gateway, middleware
Metrics Middleware, service mesh sidecars
Configuration and feature flags Shared configuration service or library

Techniques

  • Middleware / pipeline: each request passes through a chain (auth → logging → rate limit → handler). Used in ASP.NET Core, Express, Django, Rails (Rack).

  • Interceptors and filters: framework hooks around controllers or RPC calls (Spring HandlerInterceptor, gRPC interceptors).

  • AOP: declare “advice” (for example timing or transactions) that runs around matching methods, as in Spring AOP or AspectJ.

  • Decorator pattern: wrap a component with another that adds behaviour:

import functools
import time


def timed(func):
    @functools.wraps(func)
    def wrapper(*args, **kwargs):
        start = time.perf_counter()
        try:
            return func(*args, **kwargs)
        finally:
            elapsed_ms = (time.perf_counter() - start) * 1000
            print(f"{func.__name__} took {elapsed_ms:.1f} ms")   # send to metrics in real code
    return wrapper


@timed
def place_order(order_id: str) -> str:
    return f"order {order_id} placed"          # business logic stays clean


print(place_order("42"))
  • Platform level: an API gateway handles auth, rate limits and TLS for all services; a service mesh sidecar (Envoy) adds retries, mTLS and metrics without code changes.

  • Shared libraries or SDKs: one logging and tracing library used by every service, so formats and correlation IDs are consistent.

Benefits of Centralizing

  • Consistency: every endpoint is authenticated and logged the same way.

  • Clean business code: services focus on domain logic.

  • Single place to change: update the logging format or auth rules once.

  • Fewer gaps: it is harder to forget security on a new endpoint.

Trade-offs

  • Hidden behaviour: AOP and middleware make it less obvious what runs for a request; document the pipeline.

  • Order matters: authentication must run before authorization, and error handling must wrap everything.

  • Shared library coupling: upgrading a library used by fifty services is a coordinated effort; keep such libraries small and stable.

  • Gateway as a bottleneck: keep it focused on cross-cutting concerns, not business logic.

Interview Tip

Name the concerns, then the mechanisms at code level (middleware, AOP, decorators) and platform level (gateway, mesh). Interviewers like hearing that business rules never belong in middleware, and that the pipeline order matters.

11

What is the Model-View-Controller (MVC) pattern?

Model-View-Controller (MVC) is an architectural pattern for user interfaces that separates an application into three roles: the Model (data and business rules), the View (presentation of that data) and the Controller (handles input, updates the model and selects the view). The separation lets UI, input handling and business logic change and be tested independently.

Read full answer

Applies tothe pattern as used in web frameworks such as Ruby on Rails, ASP.NET Core MVC, Spring MVC, Django (which calls it MTV) and Laravel

The Three Parts

Part Responsibility Example in a blog
Model Domain data, validation, business rules, persistence mapping Post with title, body, publish! rule
View Rendering output (HTML, JSON) from model data posts/show template
Controller Receives requests, calls the model, chooses the view PostsController#show, #create

Request Flow in a Web App

  1. The browser sends GET /posts/42.

  2. The router maps it to PostsController#show.

  3. The controller loads Post 42 through the model.

  4. The controller passes the model to the view.

  5. The view renders HTML, which is returned to the browser.

For a form submission (POST /posts), the controller asks the model to validate and save, then redirects or re-renders the form with errors.

Benefits

  • Separation of concerns: designers can change templates without touching business rules.

  • Testability: models can be unit-tested; controllers tested with request specs.

  • Multiple views of the same model: an HTML page and a JSON API can share models.

  • Familiar structure: most web frameworks use it, so developers know where code belongs.

Common Problems

  • Fat controllers: business logic creeps into controllers. Keep controllers thin and move logic into models or service objects.

  • Fat models: models become huge “god objects”; extract service objects, form objects or domain services.

  • Logic in views: calculations and queries in templates; use helpers, presenters or view models.

  • Confusing MVC with system architecture: MVC structures the presentation layer; it does not decide how the overall system is divided (layers, modules, services).

Variants

Variant Difference Common in
MVP (Model-View-Presenter) Presenter drives a passive view through an interface Older Android, desktop apps
MVVM (Model-View-ViewModel) View binds to a ViewModel exposing state and commands WPF, SwiftUI, Jetpack Compose, Vue, Angular
MTV (Django) Same roles; “template” is the view, “view” is the controller Django
Client-side component models Components combine view and local logic; state in stores React, Svelte

When to Use It

  • Server-rendered web applications and APIs with a clear request-response flow.

  • Teams that benefit from framework conventions.

When Not to Rely on It Alone

  • Complex domains need structure beyond MVC: service objects, domain modules, or hexagonal architecture behind the controllers.

  • Highly interactive single-page applications usually use component-based or MVVM-style patterns.

Interview Tip

Walk through the request flow, then mention “thin controllers” and where business logic should live. Saying that MVC is a presentation-layer pattern, not the whole architecture, shows maturity.

12

How does the Publish-Subscribe pattern work in software architecture?

The Publish-Subscribe (pub-sub) pattern lets components communicate through topics or channels: publishers send messages about events without knowing who receives them, and subscribers register interest in topics and receive every matching message. A broker or event bus sits in between, which decouples senders from receivers in identity, location and often time.

Read full answer

Applies togeneral architecture pattern (examples: Apache Kafka, RabbitMQ topic exchanges, Google Cloud Pub/Sub, Amazon SNS, Redis Pub/Sub, NATS)

How It Works

  1. A publisher sends OrderPlaced to the orders topic.

  2. The broker delivers a copy to every subscription on that topic.

  3. Subscribers (billing, email, analytics) process it independently.

  4. Adding a new subscriber requires no change to the publisher.

Request flow: Order service → Broker (topic: orders) → Billing / Email / Analytics

Pub-Sub vs Point-to-Point Queue

Aspect Publish-subscribe Point-to-point queue
Receivers per message Every subscriber gets a copy One consumer gets each message
Purpose Broadcast events (fan-out) Distribute work (load balancing)
Example OrderPlaced to billing, email, analytics Image-resize jobs shared by workers

Kafka combines both: each consumer group gets every message (pub-sub across groups), while consumers within a group share the partitions (point-to-point within the group).

Applications

  • Event-driven microservices: services react to domain events instead of calling each other.

  • Notifications: push messages to users when something happens.

  • Real-time updates: live dashboards, chat rooms, stock prices (often via WebSockets fed by a pub-sub backend).

  • Cache invalidation: broadcast “product 42 changed” to all application instances.

  • Audit and analytics: copy all business events into a data platform.

  • IoT: devices publish telemetry to MQTT topics such as factory/line1/temperature.

Benefits

  • Loose coupling: publishers do not depend on subscribers.

  • Extensibility: add consumers without changing producers.

  • Scalability: subscribers scale independently.

  • Resilience: with durable brokers, a subscriber that is down catches up later.

Trade-offs

  • Eventual consistency: subscribers update after the publisher; the system must tolerate a short lag.

  • Delivery semantics: usually at-least-once, so subscribers must be idempotent; some systems (Redis Pub/Sub) are at-most-once with no persistence, so offline subscribers miss messages.

  • Ordering: guaranteed only within a partition or key, not globally.

  • Debugging: flows are implicit; you need correlation IDs and distributed tracing.

  • Schema evolution: events are contracts; version them and change them compatibly.

  • Hidden coupling: subscribers can come to depend on event details the publisher considers internal.

Design Tips

  • Name events in the past tense for things that happened (PaymentCaptured), not commands.

  • Include an event ID, timestamp, version and the entity ID.

  • Choose durable brokers (Kafka, RabbitMQ with durable queues, cloud pub-sub) for business events; lightweight ones (Redis Pub/Sub) for ephemeral signals.

  • Monitor subscriber lag and dead-letter queues.

Interview Tip

Contrast pub-sub with queues and with the Observer pattern (which is in-process and directly coupled). The common mistake is forgetting idempotency and ordering when describing an event-driven design.

13

How does microservices architecture compare with a monolith?

A monolithic architecture builds the application as one deployable unit with a shared codebase and usually one database. A microservices architecture splits it into small, independently deployable services, each owning one business capability and its own data, communicating over the network. Microservices give independent scaling and team autonomy at the cost of significant distributed-systems complexity; a monolith (ideally a modular monolith) is simpler and is the better default for most new products and small teams.

Read full answer

Applies togeneral software architecture practice

Comparison

Aspect Monolith Microservices
Deployment One unit; deploy everything together Each service deploys independently
Scaling Scale the whole app (copies behind a load balancer) Scale each service separately
Data Usually one shared database Database per service
Communication In-process function calls (fast, reliable) Network calls and messages (slower, can fail)
Consistency ACID transactions across the app Eventual consistency, sagas
Team structure Works well for one or a few teams Fits many autonomous teams
Technology One main stack Can differ per service
Operations Simple: one app to run and monitor Complex: service discovery, tracing, many pipelines
Testing Easier end-to-end testing Contract and integration testing across services
Failure isolation A bug or memory leak can affect everything Failures can be contained (with good design)
Startup cost Low High (platform, observability, CI/CD per service)

When a Monolith Is Better

  • New products where the domain is still being discovered and boundaries will change.

  • Small teams (often under 15–20 developers), where the coordination costs microservices remove do not yet exist.

  • Strong consistency needs across most of the domain.

  • Limited operations capacity.

Use a modular monolith: one deployable with strict module boundaries, so modules can later be extracted into services if needed.

When Microservices Are Better

  • Many teams need to ship independently without coordinating releases.

  • Parts of the system have very different scaling or availability needs (search traffic is 50x checkout traffic).

  • Clear, stable domain boundaries are known.

  • The organization has mature DevOps: automated pipelines, monitoring, tracing, on-call.

Costs of Microservices

  • Network unreliability: timeouts, retries, circuit breakers become mandatory.

  • Data consistency: no cross-service transactions; sagas and idempotent consumers instead.

  • Observability: you need distributed tracing and centralized logging.

  • Latency: a call chain of five services adds network hops (about 0.5 ms or more each inside a datacentre, plus serialization).

  • Distributed monolith risk: services that share a database or must deploy together get the costs of both worlds.

Migration Path

  1. Start with a modular monolith and clear bounded contexts.

  2. Extract a service only when a concrete driver appears (independent scaling, team ownership, different release cadence).

  3. Use the strangler fig pattern: route one capability at a time to the new service.

Interview Tip

Do not rank one above the other; explain the trade-off and choose based on team size, domain maturity and scaling needs. Saying “start with a modular monolith, extract services when there is a reason” is the answer most experienced interviewers expect.

14

What are the SOLID principles of object-oriented design?

SOLID is a set of five object-oriented design principles, collected by Robert C. Martin, that make code easier to change, test and extend: Single Responsibility, Open/Closed, Liskov Substitution, Interface Segregation and Dependency Inversion. They apply to classes and, at a higher level, to modules and components.

Read full answer

Applies togeneral object-oriented design (examples in Python 3.12)

The Five Principles

Principle Meaning Violation sign
*S*ingle Responsibility (SRP) A module should have one reason to change (one actor or stakeholder it serves) A class that formats reports, emails them and saves them
*O*pen/Closed (OCP) Open for extension, closed for modification Adding a payment type means editing a growing if/elif chain
*L*iskov Substitution (LSP) Subtypes must be usable wherever the base type is expected, without surprises A subclass that throws “not supported” for a base method
*I*nterface Segregation (ISP) Clients should not depend on methods they do not use A huge Repository interface every class must fully implement
*D*ependency Inversion (DIP) High-level policy depends on abstractions, not on low-level details Business logic creating a concrete database client directly

Example: OCP and DIP Together

from abc import ABC, abstractmethod


class PaymentMethod(ABC):                      # abstraction owned by the business layer
    @abstractmethod
    def charge(self, amount: float) -> str: ...


class CardPayment(PaymentMethod):
    def charge(self, amount: float) -> str:
        return f"charged {amount:.2f} to card"


class UpiPayment(PaymentMethod):               # new type added without editing Checkout (OCP)
    def charge(self, amount: float) -> str:
        return f"collected {amount:.2f} via UPI"


class Checkout:
    def __init__(self, payment: PaymentMethod) -> None:   # depends on the abstraction (DIP)
        self._payment = payment

    def pay(self, amount: float) -> str:
        return self._payment.charge(amount)


print(Checkout(CardPayment()).pay(499))
print(Checkout(UpiPayment()).pay(120))

LSP Example

A classic violation: Square inheriting from Rectangle. Code that sets width and height independently on a Rectangle breaks when given a Square, which forces both sides to be equal. Prefer composition or separate types when behaviour differs.

ISP Example

Instead of one Worker interface with work() and eat() (which a robot cannot implement meaningfully), define small interfaces such as Workable and Feedable, so each class implements only what applies.

At the Architecture Level

  • SRP becomes high cohesion: a module or service has one business purpose.

  • OCP becomes plug-in architectures and extension points.

  • ISP becomes small, client-specific APIs (for example backend-for-frontend).

  • DIP becomes hexagonal / clean architecture: the domain defines ports; infrastructure implements adapters.

Pitfalls

  • Over-application: an interface for every class and five layers for a simple script add complexity without benefit.

  • Misreading SRP as “a class should do one thing”; Martin defines it as one reason to change.

  • Abstractions too early: wait until there is a second implementation or a real testing need.

Interview Tip

Explain each principle with a short violation and fix, and say when you would not apply it. Interviewers often ask for DIP vs dependency injection: DIP is the principle (depend on abstractions); DI is a technique for supplying the implementation.

15

When should you use the Singleton pattern, and what are its drawbacks?

The Singleton pattern ensures a class has exactly one instance in a process and provides a global access point to it. It is appropriate only for things that are genuinely one per process and stateless or read-mostly, such as a configuration snapshot, a logger, or a connection pool. Its drawbacks are hidden global state, tight coupling, harder testing and concurrency issues, so in modern code it is usually better to create one instance and inject it through dependency injection.

Read full answer

Applies togeneral object-oriented design (examples in Python 3.12)

When It Fits

  • Shared, expensive resources: a database connection pool or HTTP client that should be created once and reused.

  • Process-wide services: logging, metrics registry, configuration loaded at startup.

  • Hardware or OS resources that really exist once (a printer spooler).

Even then, the single instance is the goal; the global access point is the part to avoid.

Drawbacks

Problem Why it hurts
Hidden dependencies Classes call Config.instance() internally, so their real dependencies are invisible in constructors
Global mutable state Any code can change it; bugs appear far from their cause
Hard to test Tests share state, run in order-dependent ways, and cannot easily substitute a fake
Tight coupling Code is bound to one concrete class
Concurrency Lazy creation must be thread-safe; shared mutable state needs locking
Lifecycle Hard to reset, reconfigure or dispose cleanly
“One per process” is not “one per system” In a cluster of 20 instances there are 20 singletons; it gives no cross-node uniqueness

Classic Implementation vs Dependency Injection

import threading


class Settings:
    """Classic singleton: one instance per process, created lazily and thread-safely."""
    _instance: "Settings | None" = None
    _lock = threading.Lock()

    def __init__(self) -> None:
        self.db_url = "postgres://localhost/app"

    @classmethod
    def instance(cls) -> "Settings":
        if cls._instance is None:
            with cls._lock:                       # double-checked locking
                if cls._instance is None:
                    cls._instance = cls()
        return cls._instance


# Preferred: create once at startup and pass it in explicitly
class OrderService:
    def __init__(self, settings: Settings) -> None:   # dependency is visible and replaceable
        self._settings = settings

    def describe(self) -> str:
        return f"orders stored in {self._settings.db_url}"


settings = Settings()                              # composition root creates the single instance
print(OrderService(settings).describe())
print(Settings.instance() is Settings.instance())  # True

In Python, a module-level object is already a natural singleton; frameworks like Spring and ASP.NET Core give the same effect with singleton-scoped registrations in their DI containers.

Best Practices

  • Prefer DI with a singleton lifetime over a static instance() method.

  • Keep singletons immutable or thread-safe.

  • Do not use singletons to share request or user data; that leaks state between requests.

  • For cluster-wide uniqueness (one scheduler running a job), use leader election or a distributed lock, not a Singleton class.

Interview Tip

Show you know both sides: when it fits and why it is often called an anti-pattern. A strong answer distinguishes “one instance” (fine, via DI) from “global access” (the problem), and notes that a Singleton is per process, not per system.

16

What is the Repository pattern and when should you use it?

The Repository pattern puts a collection-like interface between business logic and data storage: domain code asks a repository to add, get or find domain objects, and the repository handles the queries, mapping and persistence details. It keeps business rules independent of the database and makes them easy to test with an in-memory fake.

Read full answer

Applies togeneral architecture and design pattern (described in Martin Fowler's *Patterns of Enterprise Application Architecture* and Eric Evans's *Domain-Driven Design*)

How It Works

  • The domain layer defines an interface, for example OrderRepository with get(order_id), add(order) and find_unpaid().

  • The infrastructure layer implements it with SQL, an ORM, a document database or an external API.

  • Application services depend on the interface, not the implementation (dependency inversion).

Flow: Controller → OrderService → OrderRepository (interface) → SqlOrderRepository → Database

Example

from abc import ABC, abstractmethod
from dataclasses import dataclass


@dataclass
class Order:
    order_id: str
    total: float
    paid: bool = False


class OrderRepository(ABC):
    @abstractmethod
    def get(self, order_id: str) -> Order | None: ...
    @abstractmethod
    def add(self, order: Order) -> None: ...
    @abstractmethod
    def find_unpaid(self) -> list[Order]: ...


class InMemoryOrderRepository(OrderRepository):          # fast fake for tests
    def __init__(self) -> None:
        self._orders: dict[str, Order] = {}

    def get(self, order_id: str) -> Order | None:
        return self._orders.get(order_id)

    def add(self, order: Order) -> None:
        self._orders[order.order_id] = order

    def find_unpaid(self) -> list[Order]:
        return [o for o in self._orders.values() if not o.paid]


class PaymentReminderService:
    def __init__(self, orders: OrderRepository) -> None:
        self._orders = orders

    def reminders(self) -> list[str]:
        return [f"Reminder: order {o.order_id} ({o.total:.2f})" for o in self._orders.find_unpaid()]


repo = InMemoryOrderRepository()
repo.add(Order("1", 250.0, paid=True))
repo.add(Order("2", 99.5))
print(PaymentReminderService(repo).reminders())   # ['Reminder: order 2 (99.50)']

In production, a SqlOrderRepository would implement the same interface with real queries.

Use Cases

  • Domain-rich applications where business rules should not depend on the ORM or SQL.

  • Testability: unit-test services with in-memory repositories, without a database.

  • Multiple or changing data sources: move from one database to another, or combine a database with a cache.

  • DDD aggregates: one repository per aggregate root (OrderRepository, not OrderLineRepository).

  • Centralizing query logic so the same query is not rewritten across the codebase.

When Not to Use It

  • Simple CRUD apps: ORMs such as Active Record (Rails) or Entity Framework’s DbContext already act like repositories and units of work; wrapping them adds little.

  • Generic repositories (Repository<T> with get_all, update) that just mirror the ORM give the abstraction cost with no domain meaning.

  • Reporting and complex read queries: query services or read models (CQRS) are often clearer than forcing them through repositories.

Pitfalls

  • Leaky abstractions: returning ORM query objects (IQueryable) lets database details leak into the domain.

  • Bloated repositories with dozens of query methods; split reads into dedicated query objects.

  • Transactions: coordinate several repositories with a unit of work, not separate commits per repository.

Interview Tip

Explain the testability and decoupling benefits, then say when it is overkill. Interviewers often ask about generic repositories; explaining why they are usually an anti-pattern is a strong answer.

17

What is Service-Oriented Architecture (SOA) and what are its components?

Service-Oriented Architecture (SOA) is an architectural style in which business functionality is exposed as reusable, interoperable services with well-defined contracts, which applications combine to build business processes. Its main components are service providers, service consumers, service contracts, a service registry, and usually an enterprise service bus (ESB) that handles routing, transformation and protocol mediation.

Read full answer

Applies toSOA as practised in enterprise integration (SOAP/WSDL, ESBs, and REST-based variants)

Core Components

Component Role
Service provider Implements and hosts a service (for example “Customer Lookup”)
Service consumer Application or service that calls it
Service contract Formal interface: operations, messages, policies (WSDL + XSD, or OpenAPI)
Service registry / repository Catalogue where services are published and discovered, with versions and owners
Enterprise service bus (ESB) Middleware for routing, message transformation, protocol bridging, security and monitoring
Orchestration engine Composes services into business processes (for example BPEL or BPMN workflows)
Governance Standards, versioning rules and policies for creating and changing services

Key Principles

  • Standardized contracts shared across the organization.

  • Loose coupling between consumers and providers.

  • Abstraction: consumers see the contract, not the implementation.

  • Reusability: one “Customer” service used by many applications.

  • Composability: larger processes are built from smaller services.

  • Discoverability: services are documented and findable in a registry.

Example

A bank exposes CustomerService, AccountService and CreditCheckService. A loan-application process, orchestrated on the ESB, calls them in sequence: the ESB transforms the web portal’s request format into the mainframe’s format, routes to the right back end, and logs every step. The same CustomerService is reused by the mobile app and the call-centre system.

SOA vs Microservices (briefly)

Aspect SOA Microservices
Scope Enterprise-wide integration One application or product
Service size Often coarse-grained Fine-grained, one capability
Communication Often through a central ESB Direct calls or lightweight brokers (“smart endpoints, dumb pipes”)
Data Shared enterprise databases are common Database per service
Goal Reuse and integration of existing systems Independent deployment and team autonomy

Benefits

  • Integrates heterogeneous systems (mainframes, packaged ERP, custom apps).

  • Reuse of business capabilities across channels.

  • Central policies for security, auditing and monitoring.

Drawbacks

  • ESB bottleneck: business logic tends to accumulate in the bus, making it a fragile central point.

  • Heavy governance slows change.

  • Performance overhead of XML, transformation and extra hops.

  • Shared data models can couple many services.

When to Use It

Large organizations integrating many existing systems, with strong governance and shared business capabilities. For a single product built by autonomous teams, microservices or a modular monolith usually fit better.

Interview Tip

List the components, then compare with microservices without dismissing SOA. The common mistake is calling SOA “old microservices”; their goals differ: enterprise reuse and integration versus independent deployability.

18

How does the Decorator pattern work, with an example?

The Decorator pattern adds behaviour to an object by wrapping it in another object that implements the same interface, instead of changing its class or creating subclasses for every combination. Decorators can be stacked, so behaviours such as caching, logging, retries or compression can be combined at runtime while the wrapped object stays unchanged.

Read full answer

Applies togeneral object-oriented design pattern (Gang of Four, 1994); examples in Python 3.12

Structure

  • Component: the common interface (DataSource).

  • Concrete component: the core implementation (FileDataSource).

  • Decorator: implements the same interface and holds a reference to a component.

  • Concrete decorators: add behaviour before or after delegating (CompressionDecorator, EncryptionDecorator).

Example: Adding Caching and Retries to a Price Client

import random
from abc import ABC, abstractmethod


class PriceClient(ABC):
    @abstractmethod
    def price(self, sku: str) -> float: ...


class HttpPriceClient(PriceClient):
    """Concrete component: pretend remote call that sometimes fails."""
    def __init__(self) -> None:
        self.calls = 0

    def price(self, sku: str) -> float:
        self.calls += 1
        if random.random() < 0.3:
            raise ConnectionError("temporary failure")
        return {"BK-17": 899.0, "PN-2": 49.0}[sku]


class RetryingPriceClient(PriceClient):
    """Decorator: retries transient errors."""
    def __init__(self, inner: PriceClient, attempts: int = 5) -> None:
        self._inner, self._attempts = inner, attempts

    def price(self, sku: str) -> float:
        for attempt in range(self._attempts):
            try:
                return self._inner.price(sku)
            except ConnectionError:
                if attempt == self._attempts - 1:
                    raise
        raise AssertionError("unreachable")


class CachingPriceClient(PriceClient):
    """Decorator: caches results."""
    def __init__(self, inner: PriceClient) -> None:
        self._inner, self._cache = inner, {}

    def price(self, sku: str) -> float:
        if sku not in self._cache:
            self._cache[sku] = self._inner.price(sku)
        return self._cache[sku]


random.seed(7)
http = HttpPriceClient()
client: PriceClient = CachingPriceClient(RetryingPriceClient(http))   # stack decorators
print(client.price("BK-17"), client.price("BK-17"))   # second call served from cache
print("remote calls:", http.calls)

The caller only sees a PriceClient; it does not know that caching and retries were added.

Why Use It Instead of Subclassing

With inheritance you would need CachingHttpPriceClient, RetryingHttpPriceClient, CachingRetryingHttpPriceClient and so on: a class for every combination. Decorators give the same combinations by composition, and follow the Open/Closed Principle: new behaviour without modifying existing classes.

Real-World Uses

  • Java I/O: new BufferedReader(new InputStreamReader(new FileInputStream(f))).

  • HTTP middleware and pipelines are decorator chains around a handler.

  • Python function decorators (@functools.lru_cache, @login_required) apply the same idea to functions.

  • Resilience libraries: Resilience4j decorates calls with retries, circuit breakers and rate limiters.

Trade-offs

  • Many small objects and layers can make debugging harder.

  • Order matters: caching outside retries (as above) avoids retrying cached hits; the reverse order would behave differently.

  • Identity: the decorated object is not the same instance as the original, which matters for equality checks.

  • Decorators must support the whole interface, even methods they do not change.

Interview Tip

Explain wrapping with the same interface, show stacking, and contrast with subclass explosion. Mention that order of decorators is a design decision, which interviewers like to probe.

19

What is the Command pattern and how is it implemented?

The Command pattern turns a request into a standalone object that contains everything needed to perform it: the action, its target and its parameters. Because the request becomes an object, it can be queued, logged, scheduled, retried, undone, or sent to another process, and the code that triggers it does not need to know how it is carried out.

Read full answer

Applies togeneral object-oriented design pattern (Gang of Four, 1994); examples in Python 3.12

Roles

Role Responsibility Example
Command Interface with execute() (and often undo()) Command
Concrete command Binds an action to a receiver and parameters AddItemCommand(cart, "BK-17", 2)
Receiver Object that does the real work Cart
Invoker Triggers commands; may store history Toolbar button, job runner, CommandBus
Client Creates commands and gives them to the invoker Controller or UI code

Implementation With Undo

from abc import ABC, abstractmethod
from collections import Counter


class Cart:                                      # receiver
    def __init__(self) -> None:
        self.items: Counter[str] = Counter()


class Command(ABC):
    @abstractmethod
    def execute(self) -> None: ...
    @abstractmethod
    def undo(self) -> None: ...


class AddItem(Command):
    def __init__(self, cart: Cart, sku: str, qty: int) -> None:
        self.cart, self.sku, self.qty = cart, sku, qty

    def execute(self) -> None:
        self.cart.items[self.sku] += self.qty

    def undo(self) -> None:
        self.cart.items[self.sku] -= self.qty
        if self.cart.items[self.sku] <= 0:
            del self.cart.items[self.sku]


class Invoker:
    def __init__(self) -> None:
        self.history: list[Command] = []

    def run(self, command: Command) -> None:
        command.execute()
        self.history.append(command)              # enables undo and audit logs

    def undo_last(self) -> None:
        if self.history:
            self.history.pop().undo()


cart, invoker = Cart(), Invoker()
invoker.run(AddItem(cart, "BK-17", 2))
invoker.run(AddItem(cart, "PN-2", 5))
invoker.undo_last()
print(dict(cart.items))   # {'BK-17': 2}

Where It Is Used

  • Undo/redo in editors and design tools.

  • Job queues: a command is serialized and processed by a background worker (Sidekiq, Celery, Solid Queue jobs are command objects).

  • CQRS and command buses: PlaceOrderCommand sent to a handler, keeping controllers thin.

  • Macros and transactions: a list of commands executed as one unit, with rollback through undo.

  • GUI actions: the same “Save” command bound to a menu item, a toolbar button and a shortcut.

  • Audit logs and replay: storing executed commands shows who did what.

Benefits

  • Decouples the invoker from the receiver.

  • Extensible: add new commands without changing the invoker (Open/Closed).

  • Composable: build macro commands.

  • Supports deferred, remote and repeatable execution.

Trade-offs

  • More classes: one per action, which is overkill for simple direct calls.

  • Undo is hard when commands have external side effects (sending email cannot be undone); use compensating actions.

  • Idempotency: queued commands may be retried, so design them to be safe to run twice.

Command vs Event

A command is a request to do something (PlaceOrder) and has one handler; it may be rejected. An event reports something that already happened (OrderPlaced) and may have many subscribers.

Interview Tip

Name the roles, show undo or queuing, and contrast commands with events. A common mistake is describing it as “just a callback”; the value is that the request becomes data you can store, queue and replay.

20

When should you use the Adapter pattern?

Use the Adapter pattern when you need to make an existing class or external API work with an interface your code expects, without changing either side. An adapter wraps the incompatible component and translates calls and data between the two interfaces. It is especially useful for integrating third-party libraries, legacy systems and external services behind your own stable interface.

Read full answer

Applies togeneral object-oriented design pattern (Gang of Four, 1994); examples in Python 3.12

Typical Situations

  • Third-party SDKs: your code depends on a PaymentGateway interface, and you adapt Stripe, Razorpay or PayPal SDKs to it.

  • Legacy systems: a new service needs data from an old SOAP or mainframe API with a different model.

  • Swapping vendors: replace an email or SMS provider by writing a new adapter, without touching business code.

  • Library upgrades: wrap a library whose API changed, so the rest of the code is unaffected.

  • Testing: an adapter boundary is a natural place to plug in fakes.

  • Hexagonal architecture: “adapters” implement the ports (interfaces) defined by the domain.

Example

from abc import ABC, abstractmethod


class SmsSender(ABC):                                  # interface our app expects
    @abstractmethod
    def send(self, phone: str, text: str) -> bool: ...


class VendorSmsClient:
    """Third-party SDK with a different shape (cannot be changed)."""
    def push_message(self, payload: dict) -> dict:
        return {"status": "QUEUED", "to": payload["msisdn"]}


class VendorSmsAdapter(SmsSender):
    def __init__(self, client: VendorSmsClient) -> None:
        self._client = client

    def send(self, phone: str, text: str) -> bool:
        payload = {"msisdn": phone.replace("+", ""), "body": text[:160]}   # translate data
        response = self._client.push_message(payload)                       # translate call
        return response["status"] in {"QUEUED", "SENT"}                     # translate result


def notify_order_shipped(sms: SmsSender, phone: str) -> bool:
    return sms.send(phone, "Your order has shipped")   # business code knows only SmsSender


print(notify_order_shipped(VendorSmsAdapter(VendorSmsClient()), "+919800000000"))  # True

Object Adapter vs Class Adapter

  • Object adapter (composition, shown above): holds an instance of the adaptee. Preferred and works in every language.

  • Class adapter (inheritance): subclasses both the target and the adaptee; needs multiple inheritance and couples more tightly.

Adapter vs Similar Patterns

Pattern Purpose
Adapter Make an existing interface match another expected interface
Facade Provide a simpler interface to a complex subsystem
Decorator Add behaviour while keeping the same interface
Proxy Control access to an object with the same interface
Anti-corruption layer (DDD) An adapter at the boundary between bounded contexts that also translates the domain model

Benefits

  • Isolation of external changes to one class.

  • Reuse of existing code without modification.

  • Clean domain code that uses its own language and types.

Trade-offs and Pitfalls

  • An extra layer of indirection and mapping code.

  • Leaky adapters: exposing vendor-specific types or errors defeats the purpose; translate errors into your own exceptions too.

  • Lowest common denominator: an interface shared by many vendors may hide useful vendor features.

Interview Tip

Give a real integration example (payment or SMS providers) and connect it to hexagonal architecture’s ports and adapters. Distinguishing Adapter from Facade is a common follow-up question.

21

What strategies can be used to scale a software application?

Applications scale through vertical scaling (bigger machines), horizontal scaling (more instances behind a load balancer), and techniques that reduce or spread the load: caching, database read replicas and sharding, asynchronous processing with queues, CDNs, partitioning by function or data, and autoscaling. The right mix depends on where the bottleneck is, which you find by measuring.

Read full answer

Applies togeneral system design practice

Vertical vs Horizontal Scaling

Aspect Vertical (scale up) Horizontal (scale out)
How More CPU, RAM, faster disk More instances or nodes
Simplicity Very simple, no code changes Needs stateless services or partitioned state
Limit Hardware ceiling, cost rises steeply Near-linear, until a shared bottleneck
Availability Single point of failure Redundancy built in
Good first step for Databases, early-stage apps Web and API tiers, workers

Key Strategies

  1. Stateless application servers: keep sessions in Redis or signed cookies, so any instance can serve any request and you can add instances behind a load balancer.

  2. Caching: in-process, distributed (Redis, Memcached), HTTP caching and CDNs. A good cache can remove most database reads, but needs an invalidation and TTL plan.

  3. Database scaling:

  4. indexes and query optimization first;

  5. connection pooling;

  6. read replicas for read-heavy workloads (accepting replication lag);

  7. sharding / partitioning by key (user ID, tenant) when one primary cannot handle writes;

  8. choosing a store that fits the access pattern (for example a key-value store for sessions).

  9. Asynchronous processing: move slow work (emails, image processing, reports) to background workers via queues, so requests return fast and workers scale separately.

  10. Content delivery networks: serve static assets and cacheable pages from edge locations.

  11. Functional decomposition: split heavy components (search, media processing) into separate services that scale independently.

  12. Autoscaling: add and remove instances based on CPU, request rate or queue depth.

  13. Rate limiting and load shedding: protect the system when demand exceeds capacity.

  14. Efficient code and data: pagination, batching, compression, avoiding N+1 queries.

A Typical Path

  1. Single server: app and database together.

  2. Separate the database; scale the server vertically.

  3. Add a load balancer and several stateless app instances.

  4. Add a cache and a CDN.

  5. Add read replicas; move background work to queues.

  6. Shard the database or split out services for the hottest components.

Example Numbers

If one app instance handles 500 requests per second at 60% CPU, and peak traffic is 4,000 requests per second, you need about 8 instances at peak, plus spare capacity (say 10–12) to survive losing a zone. These are illustrative; real capacity comes from load testing.

Pitfalls

  • Scaling the wrong tier: adding app servers when the database is the bottleneck.

  • Stateful servers (local sessions, local file uploads) that block horizontal scaling.

  • Caching without invalidation, leading to stale data bugs.

  • Premature sharding, which adds huge complexity; exhaust indexes, caching and replicas first.

  • Ignoring cost: autoscaling without limits can surprise you.

Interview Tip

Start with “measure to find the bottleneck”, then walk the typical path from simple to complex. Interviewers look for trade-offs at each step, such as replication lag with read replicas and the complexity of sharding.

22

What is load balancing and why is it important in software architecture?

Load balancing distributes incoming requests or connections across multiple servers or instances, so no single server is overloaded. It is important because it enables horizontal scaling, high availability (traffic avoids failed instances through health checks), and zero-downtime deployments (instances can be drained and replaced one at a time).

Read full answer

Applies togeneral system design (examples: Nginx, HAProxy, Envoy, AWS ALB/NLB, Google Cloud Load Balancing)

Where Load Balancers Sit

Client → DNS → Load balancer → App instances → (internal load balancer) → Services / databases

Load balancing can happen at several levels: DNS (geo-routing between regions), global anycast load balancers, regional L4/L7 load balancers, and client-side balancing inside service meshes or gRPC clients.

L4 vs L7 Load Balancing

Aspect Layer 4 (transport) Layer 7 (application)
Works on TCP/UDP connections (IP, port) HTTP requests (path, headers, cookies)
Speed Very fast, low overhead More processing per request
Features Simple distribution Path-based routing, TLS termination, header rewriting, retries
Example AWS NLB, HAProxy TCP mode Nginx, Envoy, AWS ALB

Balancing Algorithms

  • Round robin: each server in turn; simple, assumes equal servers.

  • Weighted round robin: more traffic to bigger servers or during gradual rollouts.

  • Least connections / least outstanding requests: good when request durations vary.

  • IP hash / consistent hashing: the same client or key goes to the same server (cache locality).

  • Random with two choices (“power of two choices”): pick two servers at random and use the less loaded; works well at scale.

Key Features

  • Health checks: remove instances that fail checks; add them back when healthy.

  • TLS termination: decrypt at the balancer, centralizing certificates.

  • Connection draining: let in-flight requests finish before removing an instance.

  • Sticky sessions: route a user to the same instance (avoid when possible; prefer stateless servers).

  • Rate limiting and DDoS protection at the edge.

Why It Matters

  • Scalability: add instances to handle more traffic.

  • Availability: a crashed instance is removed from rotation within seconds.

  • Deployments: rolling, blue-green and canary releases depend on shifting traffic.

  • Performance: spreading load keeps latency stable.

Pitfalls

  • The load balancer as a single point of failure: run it redundantly (managed cloud load balancers are already redundant).

  • Health checks that are too shallow (process is up but the database connection is broken) or too deep (a check that fails when one optional dependency is down, removing every instance at once).

  • Sticky sessions causing uneven load and lost sessions when an instance dies.

  • Ignoring the data tier: balancing app servers does nothing if they all hit one overloaded database.

Interview Tip

Explain L4 vs L7, two or three algorithms with when to use them, and health checks. A strong answer mentions redundancy of the balancer itself and the problem with sticky sessions.

23

What is a stateless architecture?

A stateless architecture is one in which application servers keep no client-specific state between requests: every request carries all the information needed to process it (such as an authentication token), and any lasting state lives in external stores such as databases, caches or object storage. Because instances are interchangeable, any request can go to any instance, which makes horizontal scaling, failover and deployments much simpler.

Read full answer

Applies togeneral system design (applies to web servers, APIs, workers and serverless functions)

Stateful vs Stateless

Aspect Stateful servers Stateless servers
Session data In server memory In a token, Redis or a database
Load balancing Needs sticky sessions Any instance can handle any request
Scaling out Hard: state must move Easy: add instances
Instance failure Users lose sessions No user impact beyond in-flight requests
Deployments Draining is complex Replace instances freely

Where the State Goes

  • Authentication: signed tokens (JWT) or opaque session IDs looked up in Redis.

  • User sessions and carts: Redis or the database.

  • Uploaded files: object storage (S3, GCS), not the local disk.

  • Long-running workflows: a database table or a workflow engine.

  • Caches: a shared cache, or local caches that are safe to lose.

Statelessness does not mean the system has no state; it means the compute layer does not hold it.

Example

A shopping API runs 10 instances behind a load balancer. A user logs in and receives a token; their cart is stored in Redis under their user ID. Request 1 hits instance 3, request 2 hits instance 7; both read the cart from Redis. When instance 3 crashes or is replaced during a deployment, the user notices nothing.

Benefits

  • Horizontal scalability and autoscaling without data migration.

  • Resilience: instances can fail or be killed at any time.

  • Simpler load balancing: plain round robin or least-connections.

  • Fits containers and serverless, where instances are short-lived.

  • Easier testing and reasoning: requests do not depend on hidden in-memory history.

Costs and Trade-offs

  • Extra latency: each request may read state from Redis or the database (about 0.5–1 ms per round trip in one datacentre).

  • The state store becomes critical: it must be highly available and scaled.

  • Bigger requests: tokens carry data; JWTs can grow and are hard to revoke before expiry, so keep them short-lived or check a revocation list.

  • Some workloads are inherently stateful: WebSocket connections, game servers and stream processors hold state; they use partitioning, sticky routing or state checkpointing instead.

Best Practices

  • Never store session data or uploads on the local disk of app servers.

  • Make request handlers idempotent where possible, so retries to a different instance are safe.

  • Keep configuration in the environment, not on instances (twelve-factor app).

  • Treat in-process caches as optional speed-ups that can be rebuilt.

Interview Tip

Clarify that statelessness applies to the compute tier and that state moves to dedicated stores. Interviewers often ask how you handle sessions and file uploads, and what happens when an instance dies mid-request.

24

How does caching improve system performance?

Caching improves performance by storing copies of frequently used data in a faster location (memory, a nearby node or an edge server) so later requests are served without repeating expensive work such as database queries, remote calls or rendering. It lowers latency, reduces load on back-end systems and increases throughput, at the cost of possible stale data and extra complexity.

Read full answer

Applies togeneral system design (examples: Redis, Memcached, browser and HTTP caches, CDNs, database buffer pools)

Why It Helps (Rough Orders of Magnitude)

Source Typical latency
In-process memory ~100 ns
Redis in the same datacentre ~0.5–1 ms
Indexed database query ~1–10 ms
Complex query or remote API 50–500 ms
CDN edge vs distant origin ~10–30 ms vs 100–300 ms

If 90% of reads hit a 1 ms cache instead of a 20 ms query, average read latency drops from 20 ms to about 3 ms (0.9 × 1 ms + 0.1 × 21 ms, since a miss pays for the cache check too), and the database handles one tenth of the reads.

Where to Cache

  • Client / browser: HTTP Cache-Control, ETag.

  • CDN / edge: static assets and cacheable pages.

  • Application: in-process caches for small, hot, rarely changing data.

  • Distributed cache: Redis or Memcached shared by all app instances.

  • Database: buffer pool, materialized views, query result caches.

Caching Strategies

Strategy How it works Trade-off
Cache-aside (lazy loading) App checks cache; on a miss, reads the DB and fills the cache Simple; first request is slow; possible staleness
Read-through Cache library loads from the DB on a miss Cleaner code; needs cache integration
Write-through Writes go to cache and DB together Fresh cache; slower writes
Write-back (write-behind) Writes go to cache, flushed to DB later Fast writes; risk of data loss
Write-around Writes go to DB only; cache filled on read Avoids caching rarely read data

Invalidation and Eviction

  • TTL (time to live): entries expire after, say, 60 seconds; bounds staleness.

  • Explicit invalidation: delete or update the key when the data changes (often from an event).

  • Eviction policies when memory is full: LRU (least recently used), LFU (least frequently used), FIFO.

  • Versioned keys (product:42:v7) make invalidation simple.

Common Problems

  • Cache stampede: a hot key expires and thousands of requests hit the database at once. Fix with request coalescing (one rebuild per key), locks, or early probabilistic refresh, and add jitter to TTLs.

  • Stale data: users see old prices. Choose TTLs per data type and invalidate on writes.

  • Cache penetration: repeated requests for missing keys bypass the cache; cache negative results briefly.

  • Cold start: after a restart, the database takes full load; warm critical keys.

  • Inconsistency on writes: updating the DB and the cache in the wrong order causes races; prefer “update DB, then delete cache key”.

When Not to Cache

  • Data that must always be exactly current (account balances during a transfer, seat inventory at booking).

  • Data with low reuse, where most lookups miss.

  • Personal data in shared caches without proper key separation.

Interview Tip

Mention a strategy (usually cache-aside), invalidation with TTLs, eviction, and stampede protection. The classic mistake is “add Redis” with no plan for invalidation or stale data.

25

What practices are essential for designing high availability systems?

High availability (HA) means a system keeps serving users despite failures, typically measured as uptime against a target such as 99.9% (about 8.8 hours of downtime a year) or 99.99% (about 53 minutes). The essential practices are removing single points of failure with redundancy, automatic failure detection and failover, isolating failures so they do not cascade, safe deployments, and monitoring with tested recovery procedures.

Read full answer

Applies togeneral system design practice

Core Practices

  1. Redundancy everywhere: at least two instances of every component (app servers, load balancers, databases, queues), spread across availability zones; for the highest targets, across regions.

  2. Health checks and automatic failover: load balancers remove unhealthy instances; databases promote a replica when the primary fails; orchestrators (Kubernetes) restart crashed containers.

  3. Stateless services: any instance can serve any request, so losing one does not lose user sessions.

  4. Replicated data: synchronous replication for data that must not be lost (low RPO), asynchronous where some loss is acceptable; regular, restore-tested backups.

  5. Failure isolation: timeouts, retries with exponential backoff and jitter, circuit breakers, bulkheads, and rate limiting, so one slow dependency does not take everything down.

  6. Graceful degradation: turn off non-essential features (recommendations, reviews) instead of failing whole pages.

  7. Asynchronous processing: queues absorb spikes and let work continue after a component recovers.

  8. Safe deployments: rolling, blue-green or canary releases, automatic rollback, feature flags. Many outages come from changes, not hardware.

  9. Capacity headroom: enough spare capacity to lose a whole zone (often N+1 or about 50% headroom across three zones) plus autoscaling.

  10. Observability and alerting: SLOs, error budgets, dashboards, alerts on symptoms (error rate, latency) rather than only causes.

  11. Practised recovery: runbooks, on-call rotation, game days and chaos experiments, and post-incident reviews.

Availability Targets in Practice

Target Downtime per year Typical design
99% ~3.65 days Single server with backups
99.9% ~8.8 hours Redundant instances in one region, multiple zones
99.99% ~53 minutes Multi-zone with automated failover, no manual steps
99.999% ~5 minutes Multi-region active-active, extensive automation

Each extra nine usually costs much more in infrastructure and engineering effort.

Composite Availability

Dependencies in series multiply: a service needing three components at 99.9% each has at most about 99.7% availability. Redundancy in parallel improves it: two independent 99% instances give about 99.99% (if failures are truly independent, which they often are not).

Key Metrics

  • MTBF (mean time between failures) and MTTR (mean time to recovery): reducing MTTR through automation is often the cheapest win.

  • RPO (how much data you can lose) and RTO (how long recovery may take) drive replication and backup design.

Common Mistakes

  • Redundant app servers but a single database or load balancer.

  • Failover that was never tested and fails when needed.

  • Correlated failures: all replicas in one zone, or the same bad deployment pushed everywhere at once.

  • Health checks so deep that one dependency outage removes all instances.

Interview Tip

Translate the target into downtime numbers, then walk through redundancy, failover, isolation, deployment safety and testing. Interviewers like hearing that most outages are caused by changes, so release practices are part of availability.

26

What trade-offs does the CAP theorem describe?

The CAP theorem says that when a network partition splits a distributed data system, it must choose between consistency (every read sees the latest write, or gets an error) and availability (every request to a working node gets a non-error response, possibly with stale data). Partitions cannot be ruled out in real networks, so the practical trade-off is CP vs AP behaviour during a partition; when there is no partition, the PACELC extension describes a further trade-off between latency and consistency.

Read full answer

Applies todistributed data systems (CAP conjecture by Eric Brewer, 2000; proved by Gilbert and Lynch, 2002)

The Three Properties (as defined in the proof)

  • Consistency ©: linearizability; the system behaves as if there were one up-to-date copy.

  • Availability (A): every request received by a non-failing node returns a non-error response.

  • Partition tolerance (P): the system keeps operating even when messages between nodes are lost or delayed.

“Pick any two” is misleading: you cannot choose to “give up P”, because partitions happen anyway. The real question is what the system does when one happens.

CP vs AP During a Partition

Choice Behaviour during a partition Examples Good for
CP The minority side rejects or blocks requests so no conflicting writes occur etcd, ZooKeeper, Consul (Raft/Zab quorums); relational databases with synchronous failover Bank balances, inventory reservations, leader election, configuration
AP Both sides keep accepting reads and writes; conflicts are reconciled later Cassandra and DynamoDB-style stores with low consistency levels, DNS, shopping carts Social feeds, carts, metrics, presence

Many systems are tunable: Cassandra with QUORUM reads and writes behaves closer to CP for those operations; with ONE it favours availability.

PACELC: The Trade-off Without Partitions

PACELC: if there is a *P*artition, choose A or C; *E*lse, choose *L*atency or *C*onsistency.

  • Synchronous replication to a quorum gives stronger consistency but adds a network round trip to every write (about 0.5 ms in one datacentre, 50–150 ms across regions).

  • Asynchronous replication gives low latency but replicas can serve stale reads.

This “else” trade-off affects every request, so it often matters more in daily operation than the partition case.

Example: Seat Booking vs Social Likes

  • Seat booking: two users must never get the same seat. Choose CP: during a partition, a region that cannot reach the quorum returns “try again” rather than risk double booking.

  • Like counts: showing 1,203 instead of 1,205 likes for a few seconds is fine. Choose AP: accept likes everywhere and merge counters later (for example CRDT counters).

Practical Consequences

  • CP systems need quorums (a majority of 3 or 5 nodes) and lose availability on the minority side.

  • AP systems need conflict resolution: last-write-wins (can lose updates), version vectors, CRDTs or application merge logic.

  • Most real architectures mix both: CP for money and inventory, AP for caches, feeds and analytics.

  • Consistency is a spectrum: linearizable, sequential, causal, read-your-writes, eventual.

Common Mistakes

  • Saying “we choose CA” for a distributed system.

  • Confusing CAP consistency (linearizability) with ACID consistency (integrity constraints).

  • Treating a whole database as only CP or AP when its behaviour depends on configuration and operation.

Interview Tip

Lead with “during a partition, consistency or availability”, give one CP and one AP example tied to business needs, then mention PACELC. That shows you understand the real-world trade-off rather than the slogan.

27

How do you prevent single points of failure in software architecture?

A single point of failure (SPOF) is any component whose failure stops the whole system. You prevent SPOFs by finding them systematically, then adding redundancy with automatic failover for each one (instances, load balancers, databases, networks, zones, regions), removing hidden shared dependencies (one DNS provider, one secrets store, one person), and testing failover regularly so redundancy works when needed.

Read full answer

Applies togeneral system design practice

Step 1: Find the SPOFs

Walk the request path and the supporting infrastructure, asking “what happens if this disappears?”:

DNS → CDN → Load balancer → App servers → Cache → Database → Queue → External APIs

Also check the less obvious ones: TLS certificates, secrets and configuration services, the CI/CD pipeline, authentication provider, a single availability zone, a single network link, one cron server, and people (only one engineer who knows how to restore backups).

Step 2: Add Redundancy and Failover

Component SPOF fix
App servers Several stateless instances across zones behind a load balancer
Load balancer Managed, redundant load balancer, or an active-passive pair with a floating IP
Database Primary with synchronous or semi-synchronous replica and automated failover; or a distributed database with quorum replication
Cache Replicated Redis (Sentinel or cluster mode); app falls back to the database on cache failure
Message queue Clustered broker with replicated topics or quorum queues
Scheduled jobs Run on several nodes with leader election or a distributed lock, not one cron box
DNS Provider with anycast; low TTLs for failover records; for critical systems, a secondary provider
Zone / region Multi-zone by default; multi-region active-passive or active-active for the strictest targets
External dependency Timeouts, circuit breakers, fallbacks, a second provider for critical services (payments, SMS)
Storage Replicated object storage, tested backups in another region

Step 3: Make Failover Automatic and Fast

  • Health checks at every layer, with sensible thresholds.

  • Automatic promotion of database replicas, with fencing so two primaries never accept writes (avoid split brain).

  • Clients that retry another instance on failure, using idempotency keys for safe retries.

Step 4: Avoid Correlated Failures

Redundancy only helps if copies fail independently:

  • Spread replicas across zones and, where needed, regions.

  • Roll out changes gradually (canary), not to all replicas at once.

  • Avoid sharing one underlying disk, power supply, network path or configuration push.

Step 5: Test It

  • Chaos experiments: terminate instances, kill a zone in staging, block a dependency.

  • Game days: rehearse database failover and backup restores.

  • Measure detection and recovery time against your RTO.

Trade-offs

  • Cost: redundancy can double infrastructure spend; size it to the availability target.

  • Complexity: failover logic, quorum systems and multi-region data sync add operational work.

  • Consistency: replicating data across regions forces CAP and latency trade-offs.

Interview Tip

Show a methodical approach: map the path, list SPOFs including non-obvious ones (DNS, secrets, cron, people), fix each with redundancy and automated failover, and test it. Interviewers often catch candidates who make app servers redundant but forget the database or the load balancer.

28

What role does a CDN play in software architecture?

A Content Delivery Network (CDN) is a globally distributed network of edge servers that caches and serves content close to users. In an architecture it reduces latency (fewer long network trips), offloads traffic from origin servers, absorbs traffic spikes and DDoS attacks, and often provides TLS termination, compression and edge security such as a web application firewall.

Read full answer

Applies togeneral web architecture (examples: Cloudflare, Akamai, Amazon CloudFront, Fastly, Google Cloud CDN)

How It Works

  1. A user requests https://example.com/app.js; DNS (or anycast routing) sends them to a nearby edge location.

  2. If the edge has a fresh cached copy (cache hit), it returns it immediately.

  3. On a cache miss, the edge fetches from the origin (your servers or object storage), caches it according to its headers, and returns it.

  4. Later users near that edge get the cached copy.

Flow: User → Nearest CDN edge → (miss) → Origin

What a CDN Typically Serves

  • Static assets: JavaScript, CSS, images, fonts, video segments.

  • Downloads and media: software packages, streaming video (HLS/DASH segments).

  • Cacheable HTML pages for anonymous users (with short TTLs).

  • API responses that are public and cacheable.

  • Dynamic content acceleration: even uncached requests benefit from optimized routes and persistent connections between edge and origin.

Benefits

Benefit Why
Lower latency A user in Mumbai fetching from a US origin waits roughly 200+ ms per round trip; a nearby edge can answer in about 10–30 ms
Origin offload A high cache-hit ratio means most requests never reach your servers
Scalability Spikes (a viral post, a sale) are absorbed by the CDN
Availability Can serve stale content if the origin is down (stale-if-error)
Security DDoS protection, WAF rules, bot management, TLS at the edge
Cost Less bandwidth and compute at the origin

Controlling Caching

  • Cache-Control headers: public, max-age=31536000, immutable for fingerprinted assets (app.3f9a.js); s-maxage=600 for shared caches; private, no-store for personal data.

  • Cache keys: decide which parts of the URL, headers and cookies vary the cached copy; a session cookie in the key usually makes caching useless.

  • Invalidation: purge by URL or tag when content changes, or use versioned file names so new deployments never need purges.

  • Edge compute (Workers, Lambda@Edge): run small functions at the edge for redirects, A/B tests or authentication checks.

Pitfalls

  • Caching personalized pages and showing one user’s data to another. Never cache responses with Set-Cookie or user data in shared caches.

  • Stale content after deployments without versioned assets or purges.

  • Low hit ratio from query strings or headers fragmenting the cache key.

  • CDN as a dependency: a CDN outage can affect your whole site; consider fallbacks for critical systems.

Interview Tip

Explain edge caching with a latency example, the origin-offload benefit, and how Cache-Control and versioned assets keep it correct. A common mistake is forgetting that dynamic, personalized content needs private headers or careful cache keys.

29

How can database performance be optimized at the architecture level?

At the architecture level, database performance is optimized by reducing the load that reaches the database (caching, read replicas, CDNs, asynchronous processing), shaping data to the access patterns (indexes, denormalized read models, partitioning), scaling the database itself (vertical scaling, connection pooling, sharding), and choosing the right store for each workload (relational, key-value, search, analytics). Query-level tuning still matters, but architectural choices decide the ceiling.

Read full answer

Applies togeneral system design practice (examples: PostgreSQL, MySQL, Redis, Elasticsearch/OpenSearch)

1. Fix the Basics First

  • Indexes that match the most frequent queries (composite indexes in the right column order).

  • Avoid N+1 queries; fetch related data in batches or joins.

  • Pagination with keyset (“seek”) pagination instead of large OFFSET scans.

  • Connection pooling (PgBouncer, HikariCP): databases slow down with thousands of open connections.

2. Reduce Load

  • Caching: cache-aside in Redis for hot reads; HTTP and CDN caching for public pages.

  • Read replicas: send read-only queries to replicas; accept replication lag (read your own writes from the primary where needed).

  • Asynchronous writes: queue non-urgent work (analytics, audit logs) and write in batches.

  • Batching: bulk inserts and updates instead of row-by-row.

3. Shape Data for Access Patterns

  • Denormalized read models / materialized views for expensive aggregations (dashboards, feeds).

  • CQRS: separate the write model from optimized read models fed by events.

  • Partitioning large tables by time or key (for example monthly partitions for events), so queries and maintenance touch less data.

  • Archiving: move cold data to cheaper storage.

4. Scale the Database

Technique Helps with Cost
Vertical scaling Everything, quickly Hardware ceiling, cost
Read replicas Read-heavy loads Replication lag, routing logic
Sharding Write-heavy loads beyond one node Cross-shard queries, rebalancing, operational complexity
Distributed SQL (CockroachDB, Spanner, Yugabyte) Scale with SQL semantics Higher write latency, cost

5. Polyglot Persistence

Use specialized stores where they fit, keeping the relational database for transactional data:

  • Full-text search: Elasticsearch / OpenSearch instead of LIKE '%term%'.

  • Sessions and counters: Redis.

  • Analytics: a columnar warehouse (BigQuery, Snowflake, ClickHouse) instead of heavy reports on the OLTP database.

  • Time series: a time-series database or partitioned tables.

6. Observe and Iterate

  • Enable slow-query logs and EXPLAIN ANALYZE for top queries.

  • Track p95/p99 query latency, connections, lock waits, cache hit ratio and replication lag.

  • Load test with realistic data volumes; small test databases hide problems.

Example

An e-commerce site’s product pages make 40 queries each. Fixes: batch related lookups (down to 4 queries), cache product data in Redis with a 5-minute TTL and invalidation on update, move search to OpenSearch, send reports to a nightly warehouse load, and add one read replica for category browsing. The primary database now mostly handles orders and stock updates.

Common Mistakes

  • Sharding too early, before indexes, caching and replicas.

  • Running analytics on the production database.

  • Ignoring replication lag, so users do not see their own updates.

Interview Tip

Order the answer from cheap to expensive: indexes and query fixes, caching, replicas, data reshaping, then sharding. Interviewers want to hear that you measure first and know the trade-offs of each step.

30

How do database replication and failover work in an architecture?

Database replication keeps copies of data on several servers by shipping changes from one node to others, and failover is the process of switching to a replica when the primary fails. Together they provide high availability and read scaling. The key design choices are synchronous vs asynchronous replication (data-loss risk vs latency), how failure is detected, how a new primary is promoted safely, and how clients find the new primary.

Read full answer

Applies togeneral database architecture (examples: PostgreSQL streaming replication with Patroni, MySQL Group Replication / InnoDB Cluster, managed services such as Amazon RDS Multi-AZ and Aurora)

Replication Topologies

Topology How it works Use
Primary-replica (leader-follower) One primary accepts writes; replicas apply its change log Most common; read scaling + HA
Multi-primary Several nodes accept writes; conflicts must be resolved Multi-region writes (complex)
Quorum / consensus (Raft, Paxos) A write commits once a majority acknowledges Distributed SQL, etcd, CockroachDB

Synchronous vs Asynchronous

Mode Write is acknowledged when Data loss on primary failure Latency
Synchronous At least one replica has it durably None (RPO ≈ 0) Higher: adds a round trip
Semi-synchronous One replica has received it (MySQL semisync) Very small Moderate
Asynchronous The primary alone has it Recent writes may be lost Lowest

A common setup: one synchronous replica in another availability zone (no data loss), plus asynchronous replicas for reads and in another region for disaster recovery.

How Failover Works

  1. Detect that the primary is unhealthy (missed health checks over several seconds, not one blip).

  2. Elect a new primary, normally the most up-to-date replica, using a consensus-based manager (Patroni with etcd, Orchestrator, a managed service).

  3. Fence the old primary so it cannot accept writes if it comes back (shut it down, revoke its role, use leases). This prevents split brain.

  4. Promote the replica and point other replicas at it.

  5. Redirect clients: update DNS or a virtual IP, use a proxy (HAProxy, PgBouncer, ProxySQL), or rely on driver-level multi-host connection strings.

  6. Rebuild the failed node as a new replica.

Typical automated failover takes from a few seconds to a minute, depending on detection thresholds and DNS TTLs.

Application Considerations

  • Retry on connection errors with backoff, using idempotency keys so retried writes do not duplicate.

  • Replication lag: reads from async replicas can be stale; route “read your own writes” queries to the primary.

  • Connection management: pools must drop dead connections and reconnect to the new primary.

  • Do not hard-code the primary’s IP address.

Key Metrics

  • RPO (recovery point objective): how much data you can lose; drives sync vs async.

  • RTO (recovery time objective): how long the database may be unavailable; drives automation.

  • Monitor replication lag, failover duration and backup restore time.

Pitfalls

  • Untested failover, which fails during a real incident.

  • Split brain from promoting a replica without fencing the old primary.

  • Replicas in the same zone as the primary, so one zone outage takes both.

  • Treating replication as a backup: a DROP TABLE replicates instantly. Keep point-in-time backups too.

Interview Tip

Explain sync vs async in terms of RPO and latency, walk through detect, elect, fence, promote and redirect, and mention split brain. Saying “replication is not a backup” is a detail interviewers like.

31

How does cloud computing influence software architecture design?

Cloud computing shifts architecture from fixed, long-lived servers to on-demand, managed and pay-per-use resources. It encourages horizontal, elastic and stateless designs, the use of managed services (databases, queues, object storage) instead of self-run infrastructure, design for failure across zones and regions, infrastructure as code, and treating cost as an architectural quality attribute.

Read full answer

Applies togeneral architecture practice on public clouds (AWS, Azure, Google Cloud) and private clouds

Key Influences

  • Elasticity: capacity can follow demand within minutes, so architectures use autoscaling groups, Kubernetes or serverless and stateless services that can be added or removed freely.

  • Managed services: teams use managed databases, queues, caches, identity and observability, trading control for less operational work. This changes which components you build versus buy.

  • Design for failure: individual instances and even zones can disappear; architectures assume failure and use multi-zone deployments, health checks, retries and circuit breakers.

  • Global reach: regions and CDNs let you place workloads near users and meet data-residency rules.

  • Automation: infrastructure as code (Terraform, CloudFormation, Bicep, Pulumi) and CI/CD make environments reproducible.

  • New architecture styles: serverless functions, event-driven designs with managed event buses, containers and service meshes.

  • Security model: shared responsibility (provider secures the infrastructure, you secure configuration and data), identity-based access (IAM roles), encryption by default, and private networking.

  • Cost as a design driver: you pay for what you use, so choices like instance types, storage tiers, data transfer between zones and over-provisioning directly affect the bill (FinOps).

Traditional vs Cloud-Native Thinking

Aspect Traditional data centre Cloud-native
Capacity Bought for peak, months ahead On demand, autoscaled
Servers Long-lived, hand-configured (“pets”) Disposable, rebuilt from code (“cattle”)
Failure handling Avoid failure with expensive hardware Expect failure; recover automatically
Components Self-hosted everything Managed services where sensible
Deployments Infrequent, manual Frequent, automated pipelines
Cost model Capital expense Operating expense, usage-based

Example

A media company moves video processing to the cloud: uploads go to object storage, an event triggers a queue, containerized workers scale from 2 to 200 based on queue depth, results go to a CDN, and everything is defined in Terraform. They pay for heavy compute only during busy hours.

Trade-offs and Risks

  • Vendor lock-in: deep use of proprietary services makes migration expensive; isolate them behind interfaces where it matters, but do not avoid managed services out of fear alone.

  • Cost surprises: data egress, chatty cross-zone traffic and idle resources add up; monitor costs per service.

  • Distributed complexity: networking, IAM and many managed services need expertise.

  • Latency and limits: managed services have quotas and network hops; design within them.

  • Compliance: data residency and regulatory requirements affect region and service choices.

Interview Tip

Connect cloud features to architecture decisions: elasticity leads to stateless services, failure-prone infrastructure leads to multi-zone redundancy, pay-per-use makes cost a quality attribute. A strong answer also names lock-in and cost control as trade-offs.

32

What is Infrastructure as Code and how does it relate to architecture?

Infrastructure as Code (IaC) means defining infrastructure (networks, servers, databases, load balancers, permissions) in version-controlled code or configuration files that tools apply automatically, instead of configuring it by hand. It relates to architecture because it makes the deployment architecture explicit, reviewable, reproducible and testable: the code is the current description of how the system runs.

Read full answer

Applies totools such as Terraform / OpenTofu, AWS CloudFormation and CDK, Azure Bicep, Pulumi, Ansible; Kubernetes manifests and Helm charts

Declarative vs Imperative

Style You describe Examples
Declarative The desired end state; the tool works out the changes Terraform, CloudFormation, Bicep, Kubernetes YAML
Imperative Steps to run, in order Shell scripts, some Ansible playbooks

Declarative tools are the norm for cloud infrastructure, because they compute a plan (what will be created, changed or destroyed) before applying it.

Example (Terraform)

resource "aws_s3_bucket" "uploads" {
  bucket = "acme-prod-uploads"
}

resource "aws_s3_bucket_versioning" "uploads" {
  bucket = aws_s3_bucket.uploads.id
  versioning_configuration {
    status = "Enabled"            # keep old object versions for recovery
  }
}

resource "aws_s3_bucket_public_access_block" "uploads" {
  bucket                  = aws_s3_bucket.uploads.id
  block_public_acls       = true
  block_public_policy     = true
  ignore_public_acls      = true
  restrict_public_buckets = true
}

This file documents and enforces architectural decisions: uploads are private and versioned.

How IaC Supports Architecture

  • Architecture as executable documentation: network boundaries, redundancy across zones, and which services can talk to which are visible in code, not in outdated diagrams.

  • Consistency across environments: dev, staging and production are built from the same modules with different parameters, which reduces “works in staging” surprises.

  • Reviewable decisions: changes go through pull requests and plans, so architects can review a new public endpoint or an open security group before it exists.

  • Reusable building blocks: modules encode approved patterns (a standard service with a load balancer, autoscaling, logging and alarms).

  • Disaster recovery: environments can be recreated in another region from code.

  • Policy as code: tools such as Open Policy Agent, Checkov or Sentinel enforce rules (encryption on, no public buckets) automatically.

  • Evolution: architecture changes become small, tracked, reversible commits.

Best Practices

  • Keep state safe: remote, locked, encrypted state storage for Terraform.

  • Modules with clear inputs and outputs, versioned like libraries.

  • No manual changes in the console; detect drift and reconcile it.

  • Secrets stay out of code; reference a secrets manager.

  • Pipeline-driven applies with plan review and approvals for production.

  • Small blast radius: split state by environment and component, so one change cannot destroy everything.

Trade-offs

  • Learning curve and tool-specific languages.

  • State management issues (locking, drift, accidental destruction).

  • Slow feedback for large stacks.

  • Abstraction leaks: provider limits and quirks still matter.

Interview Tip

Describe IaC as making the deployment architecture explicit, reproducible and reviewable, not just “automation”. Mention plans, modules, drift and policy as code. A common mistake is mixing manual console changes with IaC, which creates drift.

33

What role do microservices play in cloud-native design?

In cloud-native design, microservices are the usual unit of deployment: small, independently deployable services, each owning one business capability and its data, packaged in containers, run by an orchestrator such as Kubernetes, and connected through APIs and events. Combined with automation and observability, they let teams release, scale and recover each part of a system independently.

Read full answer

Applies tocloud-native practice as described by the CNCF (containers, Kubernetes, service meshes, managed cloud services)

What “Cloud-Native” Adds to Microservices

Cloud-native element Role for microservices
Containers (Docker / OCI images) Consistent, immutable packaging for each service
Orchestration (Kubernetes) Scheduling, self-healing, rolling updates, service discovery, autoscaling
Declarative configuration and IaC Every service and its infrastructure defined in code
CI/CD pipelines Each service built, tested and deployed on its own
Service mesh / API gateway Traffic routing, mTLS, retries, rate limiting
Managed backing services Databases, queues, caches per service without running them yourself
Observability Centralized logs, metrics and distributed tracing across services

Characteristics of a Cloud-Native Microservice

  • Single business capability (orders, payments, catalog), aligned to a bounded context.

  • Owns its data: no shared database with other services.

  • Stateless compute, with state in managed stores, so instances can be added or replaced at any time.

  • Configuration from the environment (twelve-factor app principles).

  • Health endpoints (liveness and readiness probes) for the orchestrator.

  • Resilient communication: timeouts, retries with backoff, circuit breakers, idempotent handlers.

  • Fast startup and graceful shutdown, so autoscaling and deployments are quick.

  • Emits telemetry: structured logs, metrics, traces with correlation IDs.

Example Flow

Client → API gateway → Orders service (Kubernetes Deployment, 3–20 pods) → publishes OrderPlaced → Kafka → Payments and Notifications services

Each service has its own pipeline, container image, database and autoscaling rule; the orders team can deploy ten times a day without coordinating with the payments team.

Benefits

  • Independent deployability and scaling per service.

  • Fault isolation: a failing recommendation service does not take down checkout.

  • Team autonomy: one team owns a service end to end (“you build it, you run it”).

  • Technology choice per service, within sensible limits.

Costs

  • Operational complexity: many pipelines, images, dashboards and alerts.

  • Distributed-systems problems: network failures, eventual consistency, versioning of APIs and events.

  • Platform investment: Kubernetes, observability and security tooling need a platform team or managed services.

  • Latency from network hops between services.

When It Fits

Large or growing organizations with several teams, clear domain boundaries, and different scaling needs per capability. For small teams, a modular monolith in a container on a managed platform gives most cloud-native benefits with much less complexity.

Interview Tip

Explain how containers, orchestration, CI/CD and observability make microservices practical, then state the costs. Interviewers like candidates who say cloud-native does not require microservices; it requires automation, elasticity and resilience.

34

What is containerization and what are its architectural benefits?

Containerization packages an application together with its runtime, libraries and configuration into a container image that runs as an isolated process sharing the host’s operating-system kernel. The same image runs identically on a laptop, a CI server and production. Architecturally, containers give consistent environments, fast and dense deployment, immutable releases and a standard unit for orchestration, scaling and microservices.

Read full answer

Applies toOCI-compatible containers (Docker, containerd, Podman) and orchestrators such as Kubernetes

How Containers Work

  • Images are built in layers from a Dockerfile and stored in a registry.

  • At runtime, Linux namespaces isolate processes, networking and file systems, and cgroups limit CPU and memory.

  • Containers share the host kernel, so they start in seconds (or less) and use far less memory than virtual machines.

Containers vs Virtual Machines

Aspect Containers Virtual machines
Isolation Process-level, shared kernel Full guest OS on a hypervisor
Startup Milliseconds to seconds Tens of seconds to minutes
Size Tens to hundreds of MB Several GB
Density Many per host Fewer per host
Security boundary Weaker (kernel shared) Stronger

Many platforms combine them: containers run inside VMs, or in lightweight micro-VMs (Firecracker, gVisor sandboxes) for stronger isolation.

Example Dockerfile

FROM python:3.12-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
RUN useradd --create-home appuser
USER appuser                       # do not run as root
EXPOSE 8000
CMD ["gunicorn", "-b", "0.0.0.0:8000", "app:app"]

Architectural Benefits

  • Environment consistency: removes “works on my machine”; dependencies are fixed in the image.

  • Immutable deployments: a release is an image tag; rollback means redeploying the previous tag.

  • Fast scaling: new instances start quickly, so autoscaling responds to spikes.

  • Higher density and lower cost: more workloads per server.

  • Isolation of dependencies: services with different language versions run side by side.

  • Standard unit for orchestration: Kubernetes, ECS, Cloud Run and Nomad schedule, heal and scale containers.

  • Portability: the same image runs on any cloud or on-premises platform that supports OCI images.

  • Supports microservices and CI/CD: each service has its own image and pipeline.

Trade-offs and Pitfalls

  • Weaker isolation than VMs: harden containers (non-root user, read-only file system, minimal base images, dropped capabilities).

  • Image hygiene: large or outdated images carry vulnerabilities; scan images and rebuild regularly.

  • State: containers are ephemeral; keep data in volumes or external stores.

  • Operational complexity: networking, storage and orchestration need expertise.

  • Not a silver bullet: containerizing a poorly structured monolith keeps its problems, just in a box.

Interview Tip

Explain namespaces and cgroups briefly, compare containers with VMs, and connect benefits to architecture (immutability, scaling, orchestration). Distinguishing Docker (building and running containers) from Kubernetes (orchestrating many of them) is a common follow-up.

35

How does CI/CD influence architectural design?

CI/CD (continuous integration and continuous delivery or deployment) is the practice of automatically building, testing and releasing every change through a pipeline. It shapes architecture because systems must be designed to be released often and safely: independently deployable components, backward-compatible interfaces and database migrations, strong automated tests at the right levels, configuration outside the code, and runtime controls such as feature flags and gradual rollouts.

Read full answer

Applies togeneral software delivery practice (examples: GitHub Actions, GitLab CI, Jenkins, Argo CD)

What CI/CD Includes

  • Continuous integration: every commit is merged frequently and verified by an automated build and test run.

  • Continuous delivery: every change that passes is releasable at any time, usually with a manual approval.

  • Continuous deployment: passing changes go to production automatically.

Architectural Requirements It Creates

Requirement Architectural response
Release one part without others Modular boundaries; independently deployable services or modules
Fast feedback Fast unit tests for business logic, contract tests between services, few slow end-to-end tests
Zero-downtime releases Stateless services, rolling, blue-green or canary deployments, health checks
Mixed versions running at once Backward-compatible APIs and events; expand-and-contract database migrations
Safe experimentation Feature flags to separate deploy from release
Same artifact everywhere Immutable build artifacts (container images); environment-specific configuration
Reproducible environments Infrastructure as code
Quick recovery Automated rollback, observability and alerting tied to releases

Example: Expand and Contract

To rename a column without downtime while old and new versions run together:

  1. Expand: add the new column; the new code writes both columns.

  2. Migrate: backfill existing rows.

  3. Switch reads to the new column.

  4. Contract: remove the old column in a later release, once no running code uses it.

This pattern exists because CI/CD means old and new code overlap during every deployment.

How It Pushes Architecture

  • Toward smaller, decoupled components: a pipeline that takes two hours and needs ten teams to approve is a sign of a tightly coupled architecture.

  • Toward testability: hexagonal or clean architectures make business rules testable without infrastructure.

  • Toward observability: frequent releases need metrics and traces to detect bad deploys within minutes.

  • Conway’s law in reverse: teams that deploy independently push for boundaries that let them do so.

Pitfalls

  • A “microservices” architecture where every release still requires deploying all services together (a distributed monolith).

  • Flaky or slow test suites that teams learn to ignore.

  • Breaking API or schema changes without versioning.

  • Long-lived branches that defeat continuous integration.

Interview Tip

Show the two-way relationship: CI/CD needs a deployable, testable architecture, and the architecture benefits from fast, safe releases. Mentioning expand-and-contract migrations and feature flags gives concrete evidence of experience.

36

How do serverless architectures work, and what are their benefits?

In a serverless architecture, you deploy functions or containers that the cloud provider runs on demand in response to events (HTTP requests, queue messages, file uploads, schedules). The provider handles servers, scaling and patching; you pay per execution rather than for idle capacity. Serverless usually also includes managed backends: databases, queues, storage and authentication that scale automatically.

Read full answer

Applies toFunction-as-a-Service and serverless container platforms such as AWS Lambda, Azure Functions, Google Cloud Run functions, Cloudflare Workers, and serverless containers (Cloud Run, AWS Fargate)

How It Works

  1. You deploy code (a function handler or container image) and configure triggers.

  2. When an event arrives, the platform finds or starts an execution environment and runs the handler.

  3. Under load, the platform runs many instances in parallel; with no traffic, it scales to zero (on most platforms).

  4. Functions are stateless; state lives in managed services (DynamoDB, S3, Redis, a SQL database).

  5. You are billed for invocations and compute time (for example GB-seconds), not idle servers.

Example flow: User uploads image → S3 event → resize function → writes thumbnail to S3 → publishes event → notification function

Benefits

  • No server management: no OS patching, capacity planning or cluster upkeep.

  • Automatic scaling: from zero to thousands of concurrent executions.

  • Cost efficiency for spiky or low traffic: no charge when idle.

  • Fast delivery: small units of code focused on business logic.

  • Built-in high availability across zones, provided by the platform.

  • Natural fit for event-driven designs with managed queues and event buses.

Drawbacks

Drawback Detail
Cold starts First request after idle may take extra time (from tens of ms to seconds, depending on runtime and package size)
Execution limits Maximum duration (for example 15 minutes on AWS Lambda), memory and payload limits
Cost at steady high load Per-request pricing can exceed always-on containers or VMs
Vendor lock-in Triggers, permissions and event formats are provider-specific
Debugging and testing Harder to reproduce locally; distributed tracing needed
Connection management Many short-lived instances can exhaust database connections; use proxies or HTTP-based data APIs
Complexity spread Hundreds of small functions can become hard to understand

When to Use It

  • Event processing: file uploads, webhooks, queue consumers, scheduled jobs.

  • APIs with variable or unpredictable traffic.

  • Glue code and automation between managed services.

  • Prototypes and products where speed matters more than fine-grained control.

When Not to Use It

  • Long-running or CPU-heavy jobs beyond time limits.

  • Very latency-sensitive paths where cold starts are unacceptable (unless you pay for provisioned concurrency).

  • High, steady throughput where reserved capacity is cheaper.

  • Workloads needing special hardware or OS control.

Best Practices

  • Keep functions small, stateless and idempotent (events can be delivered more than once).

  • Minimize package size and initialization work to reduce cold starts.

  • Use dead-letter queues for failed events.

  • Define everything with infrastructure as code.

  • Monitor cost per function and set concurrency limits to protect downstream systems.

Interview Tip

Explain the event-driven execution model, the pay-per-use benefit and the trade-offs (cold starts, limits, lock-in, cost at scale). Interviewers like hearing that “serverless” means you do not manage servers, not that there are none.

37

What is feature toggling and how does it support DevOps?

Feature toggling (feature flags) means wrapping new or changing functionality in runtime conditions that can be switched on or off without deploying new code. It supports DevOps by separating deployment from release: code can be merged and deployed continuously while features are hidden, then released gradually, tested in production, and turned off instantly if something goes wrong.

Read full answer

Applies togeneral delivery practice (tools such as LaunchDarkly, Unleash, Flagsmith, OpenFeature-based SDKs, or a simple in-house flag store)

Types of Toggles

Type Purpose Lifetime
Release toggle Hide unfinished features while trunk-based development continues Days to weeks; remove after launch
Experiment toggle A/B tests; different variants for user segments Duration of the experiment
Ops toggle (kill switch) Turn off expensive or risky functionality under load or during incidents Long-lived
Permission toggle Enable features for specific plans, beta users or internal staff Long-lived

(Categories as described by Pete Hodgson.)

How It Supports DevOps

  • Trunk-based development: no long-lived feature branches; incomplete code ships “dark”.

  • Progressive delivery: release to 1% of users, then 10%, then 100%, watching error rates.

  • Fast rollback: turning a flag off is quicker and safer than redeploying.

  • Testing in production: internal users try a feature on real data before customers do.

  • Incident response: kill switches disable non-critical features to protect core flows.

  • Business control: product teams can schedule launches without engineering deployments.

Example

import hashlib


FLAGS = {"new_checkout": {"enabled": True, "rollout_percent": 10}}


def is_enabled(flag: str, user_id: str) -> bool:
    config = FLAGS.get(flag)
    if not config or not config["enabled"]:
        return False
    # Stable bucketing: the same user always gets the same answer
    bucket = int(hashlib.sha256(f"{flag}:{user_id}".encode()).hexdigest(), 16) % 100
    return bucket < config["rollout_percent"]


def checkout(user_id: str) -> str:
    if is_enabled("new_checkout", user_id):
        return "new checkout flow"
    return "old checkout flow"


users = [f"user-{i}" for i in range(1000)]
share = sum(is_enabled("new_checkout", u) for u in users) / len(users)
print(checkout("user-7"), f"| rollout share ~ {share:.0%}")

Architectural Considerations

  • Central flag service with SDKs that cache flags locally, so flag checks are fast and survive a flag-service outage (with safe defaults).

  • Evaluate flags at the edges (controllers, composition roots) rather than deep inside domain logic, to limit branching.

  • Consistent assignment per user (hashing), so users do not flip between variants.

  • Audit log of flag changes, since a flag change is effectively a production change.

Pitfalls

  • Flag debt: old flags left in code create complexity and dead paths. Track owners and expiry dates; remove release flags after launch.

  • Combinatorial testing: many interacting flags create untested combinations; test the important ones.

  • Security: do not rely on client-side flags to hide data the user should not access; enforce permissions on the server.

  • Database changes still need backward-compatible migrations; a flag cannot undo a destructive schema change.

Interview Tip

Explain “deploy is not release”, the toggle types, and flag debt. Interviewers often ask how you avoid toggle sprawl; owners, expiry dates and removal tickets are the expected answer.

38

How do you add monitoring and logging to a cloud-based architecture?

In a cloud architecture, monitoring and logging are built in as an observability layer: every service emits structured logs, metrics and distributed traces with shared correlation IDs, a collector (often OpenTelemetry) ships them to central stores, and dashboards, SLO-based alerts and on-call processes turn that data into action. The goal is to detect problems quickly and find their cause across many short-lived instances and managed services.

Read full answer

Applies tocloud-native observability practice (examples: OpenTelemetry, Prometheus and Grafana, Elasticsearch/OpenSearch, Loki, Jaeger/Tempo, CloudWatch, Azure Monitor, Google Cloud Operations, Datadog)

The Three Signal Types

Signal Answers Example
Metrics Is something wrong? How much? Request rate, error rate, p99 latency, CPU, queue depth
Logs What exactly happened? {"level":"error","order_id":"42","msg":"payment declined"}
Traces Where did the time go across services? A checkout request spanning gateway, orders, payments, database

Architecture

Services (OpenTelemetry SDKs) → Collector / agent → Metrics store, Log store, Trace store → Dashboards and alerting → On-call

  • Instrumentation: OpenTelemetry SDKs or auto-instrumentation for HTTP, database and queue clients.

  • Collection: agents or sidecars (OpenTelemetry Collector, Fluent Bit) buffer, enrich (add service, version, region) and forward data.

  • Storage: a time-series database for metrics, a log store with retention policies, a trace backend with sampling.

  • Managed-service telemetry: enable provider metrics and logs for load balancers, databases and queues.

Key Practices

  1. Structured logging (JSON) with consistent fields: timestamp, level, service, version, trace ID, request ID, user or tenant ID where allowed.

  2. Correlation: propagate trace context (W3C traceparent header) through HTTP calls and message headers, so logs and traces link up.

  3. Golden signals / RED metrics for every service: request rate, errors, duration (latency), plus saturation (CPU, memory, connections, queue depth).

  4. SLOs and error budgets: for example “99.9% of checkout requests succeed within 500 ms over 30 days”; alert when the budget burns too fast.

  5. Alert on symptoms, not every cause: page on user-facing error rate or latency; send lower-priority notifications for disk usage trends.

  6. Dashboards per service and per user journey.

  7. Deployment markers on dashboards, so you can see whether a release caused a change.

  8. Retention and cost control: sample traces (for example keep all errors and a few percent of successes), drop debug logs in production, tier old data.

  9. Security: never log passwords, tokens or full card numbers; mask personal data; restrict access to logs.

  10. Audit logs for security-relevant actions, stored separately and immutably.

Example Alert

“Page on-call if the checkout error rate is above 2% for 5 minutes, or if the 1-hour error-budget burn rate exceeds 14x.” This catches real incidents without paging on brief spikes.

Pitfalls

  • Logs on local container disks that vanish when pods are replaced.

  • High-cardinality metric labels (user IDs) that explode storage costs.

  • Too many alerts, so on-call engineers ignore them (alert fatigue).

  • No trace propagation through queues, which breaks end-to-end visibility.

Interview Tip

Name the three signals, OpenTelemetry for instrumentation, correlation IDs, and SLO-based alerting. A strong answer also mentions cost control (sampling, retention) and keeping sensitive data out of logs.

39

What is blue-green deployment and how does it minimize downtime?

Blue-green deployment runs two identical production environments: blue serves live traffic while green receives the new release. After green is deployed and verified, traffic is switched to green in one step (at the load balancer, router or DNS). Users see no downtime, and if a problem appears, traffic is switched back to blue almost instantly.

Read full answer

Applies togeneral deployment practice (load balancers, Kubernetes services, AWS CodeDeploy, Azure App Service deployment slots, Argo Rollouts)

How It Works

  1. Blue (version 1) handles all production traffic.

  2. Deploy version 2 to green, which is identical in size and configuration.

  3. Run smoke tests and health checks against green using internal routes.

  4. Switch traffic from blue to green: change the load balancer target group, the Kubernetes Service selector, or a router rule.

  5. Monitor error rates and latency.

  6. If problems appear, switch back to blue. If all is well, keep blue idle for a while as a rollback option, then use it for the next release.

Why It Minimizes Downtime

  • The new version is fully running and warmed up before it receives traffic, so there is no gap while servers restart.

  • The switch is atomic from the user’s point of view.

  • Rollback is a routing change, not a redeployment, taking seconds rather than minutes.

  • Releases can be tested in a production-identical environment.

Comparison With Other Strategies

Strategy How traffic moves Rollback speed Extra capacity Risk exposure
Blue-green All at once, between two environments Very fast 2x during deploy All users at switch time
Rolling Instance by instance Slower (roll back each instance) Little Mixed versions running together
Canary Small percentage first, then more Fast Small Only a fraction of users at first
Recreate Stop old, start new Slow None Downtime

Blue-green can be combined with canary steps: send 5% of traffic to green first, then 100%.

The Hard Parts

  • Databases: both environments usually share one database, so schema changes must work with both versions (expand-and-contract migrations). A destructive migration makes rollback impossible.

  • Sessions and in-flight requests: use stateless services and connection draining so users are not logged out or cut off.

  • Background workers and queues: make sure blue and green do not both process the same jobs in incompatible ways; switch workers carefully.

  • Cost: two full environments during deployments (cloud elasticity reduces this, since green can be created only for the release).

  • DNS-based switching is slow because of caching; prefer load-balancer or router switching.

Example

An e-commerce API runs on Kubernetes with a Service selecting pods labelled version: blue. The team deploys a green Deployment, runs automated checks against it, then updates the Service selector to version: green. When error rates rise after the switch, they change the selector back within seconds.

Interview Tip

Explain the two environments, the atomic switch and instant rollback, then the database compatibility problem. Interviewers almost always ask about database migrations; expand-and-contract is the expected answer.

40

What are the approaches to multi-tenancy in cloud applications?

Multi-tenancy means one application instance or platform serves many customers (tenants) while keeping their data and configuration isolated. The main approaches differ by what is shared: a shared database with a tenant ID column (pool model), a schema per tenant, a database per tenant, or fully separate stacks per tenant (silo model). The choice trades cost and operational simplicity against isolation, compliance and noisy-neighbour risk.

Read full answer

Applies toSaaS architecture practice on any cloud

The Main Models

Model How it works Isolation Cost per tenant Operations Best for
Shared everything (pool) One database, every table has tenant_id Lowest (logical) Lowest Simplest to run, migrations once Many small tenants
Schema per tenant One database, separate schema per tenant Medium Low–medium Migrations per schema Hundreds of mid-size tenants
Database per tenant Separate database per tenant on shared servers High Medium–high Many databases to manage Regulated or large tenants
Silo (stack per tenant) Separate compute and data per tenant Highest Highest Most complex Enterprise customers with strict requirements
Hybrid / tiered Pool for small tenants, silo for premium ones Varies Varies Two operating models Most mature SaaS products

Key Design Concerns

  • Tenant context: identify the tenant on every request (subdomain, token claim, header) and carry it through the call chain, background jobs and events.

  • Data isolation:

  • In the pool model, every query must filter by tenant_id. Enforce it centrally (ORM default scopes, repository layer) and ideally in the database with row-level security (PostgreSQL RLS).

  • Include the tenant in cache keys, search indexes and file paths.

  • Noisy neighbours: one large tenant can slow others. Use per-tenant rate limits, quotas, separate queues for heavy jobs, and move big tenants to dedicated resources.

  • Security: tenant-scoped authorization, per-tenant encryption keys where required, and tests that try to read across tenants.

  • Customization: per-tenant configuration and feature flags rather than code forks.

  • Operations: migrations across many schemas or databases, per-tenant backup and restore, onboarding and offboarding automation, data export and deletion.

  • Observability and billing: tag metrics and logs with tenant IDs (carefully, because of cardinality), and meter usage per tenant.

  • Compliance: data residency (EU tenants in EU regions) may force regional or siloed deployments.

Example

A B2B invoicing SaaS starts with the pool model on PostgreSQL with RLS policies such as tenant_id = current_setting('app.tenant_id'). Each request sets the tenant at the start of its database transaction. Two years later, three enterprise customers need dedicated databases for compliance; the app routes them through a tenant catalogue that maps each tenant to its database connection.

Pitfalls

  • Missing tenant filters in one query, leading to cross-tenant data leaks (the most serious multi-tenancy bug).

  • Background jobs without tenant context.

  • Schema per tenant at very large scale (tens of thousands of schemas strain the database and slow migrations).

  • Designing silo-first for a product with thousands of small customers, making it too expensive to operate.

Interview Tip

Compare the models in a table, say which you would choose for a given customer profile, and stress isolation enforcement (row-level security, scoped caches) and noisy-neighbour control. Many interviewers also ask how you would move a tenant from the pool to a dedicated database.

41

What is a data lake and what role does it play in architecture?

A data lake is a central repository that stores large volumes of raw data in its original format (structured, semi-structured and unstructured), usually on cheap, scalable object storage such as Amazon S3, Azure Data Lake Storage or Google Cloud Storage. Structure is applied when the data is read (schema-on-read). In an architecture it is the landing and history layer for analytics, data science and machine learning, decoupled from operational databases.

Read full answer

Applies tomodern data architecture (object storage with open table formats such as Apache Iceberg, Delta Lake and Apache Hudi; engines such as Spark, Trino, Athena, Databricks, Snowflake external tables)

Data Lake vs Data Warehouse

Aspect Data lake Data warehouse
Data Raw, any format (JSON, CSV, Parquet, logs, images) Cleaned, modelled, structured
Schema On read On write
Storage cost Low (object storage) Higher
Users Data engineers, data scientists, ML Analysts, BI dashboards
Strength Flexibility, history, scale Fast, consistent SQL analytics
Risk Becoming a disorganized “data swamp” Rigid, slower to add new sources

A lakehouse combines them: open table formats add ACID transactions, schema evolution and time travel on top of lake storage, so BI-style SQL can run directly on lake data.

Typical Layout (Medallion Architecture)

  1. Bronze / raw: data exactly as ingested (CDC streams, API dumps, logs), immutable and partitioned by date.

  2. Silver / cleaned: deduplicated, validated, conformed types and keys.

  3. Gold / curated: business-level tables and aggregates for reporting and ML features.

Role in an Architecture

  • Decouples analytics from operations: heavy analytical queries no longer run on production databases.

  • Single source of history: keeps raw data so new questions can be answered and pipelines reprocessed later.

  • Integrates many sources: application databases (via change data capture), event streams (Kafka), SaaS tools, files, clickstreams.

  • Feeds ML: training data and feature pipelines.

  • Cheap long-term retention for compliance and audits.

Flow: Operational DBs, events, SaaS APIs → Ingestion (batch / streaming) → Lake (bronze → silver → gold) → Warehouse / BI / ML

Governance Essentials

  • Catalogue and metadata (AWS Glue, Unity Catalog, Apache Atlas, DataHub) so data can be found and understood.

  • Access control at table and column level; mask or tokenize personal data.

  • Data quality checks in pipelines.

  • Lineage: where each dataset came from and what depends on it.

  • Retention and deletion processes that satisfy privacy laws (the right to erasure is hard with immutable raw files; plan for it).

Pitfalls

  • Data swamp: data dumped without ownership, documentation or quality, so nobody trusts it.

  • Small files (millions of tiny objects) that make queries slow; compact into larger Parquet files.

  • Treating the lake as an operational database; it is for analytics, not low-latency transactions.

  • Security gaps: one bucket with broad access exposing sensitive data.

Interview Tip

Contrast lake and warehouse, mention schema-on-read, the medallion layers and the lakehouse trend. Interviewers often ask how to stop a lake becoming a swamp: ownership, cataloguing, quality checks and governance.

42

What is the difference between ETL and ELT?

ETL (Extract, Transform, Load) transforms data before loading it into the target, typically on a separate processing server. ELT (Extract, Load, Transform) loads raw data first into a powerful target such as a cloud data warehouse or lakehouse, then transforms it inside that target using SQL. ELT has become the common choice with cloud warehouses because their compute scales on demand; ETL remains useful when data must be cleaned, filtered or masked before it reaches the target.

Read full answer

Applies todata integration practice (ETL tools such as Informatica, Talend, SSIS; ELT stacks such as Fivetran or Airbyte plus dbt on Snowflake, BigQuery, Redshift or Databricks)

How Each Works

ETL

  1. Extract from source systems.

  2. Transform on an ETL server or engine (clean, join, aggregate, mask).

  3. Load the finished tables into the warehouse.

ELT

  1. Extract from source systems.

  2. Load raw data into staging tables in the warehouse or lake.

  3. Transform with SQL inside the warehouse (often managed with dbt) into cleaned and modelled tables.

Comparison

Aspect ETL ELT
Where transformation runs Separate ETL engine Inside the warehouse / lakehouse
Raw data kept in target Usually not Yes, so it can be reprocessed
Time to load new sources Slower: transformations designed first Faster: load first, model later
Scalability Limited by the ETL server Uses elastic warehouse compute
Flexibility Changing logic means re-extracting Re-run SQL on stored raw data
Data privacy Sensitive fields can be removed before loading Raw (possibly sensitive) data lands in the target; needs controls
Cost profile ETL infrastructure and licences Warehouse compute and storage
Typical tools Informatica, SSIS, Talend, custom Spark jobs Fivetran/Airbyte + dbt, warehouse SQL
Best fit On-premises warehouses, strict pre-load compliance, heavy non-SQL transforms Cloud warehouses, analytics engineering, fast-changing requirements

Example

A retailer combines orders from PostgreSQL, ad spend from a marketing API and clickstream events:

  • ETL approach: a nightly job joins and aggregates everything on an ETL server and loads only daily summary tables. Adding a new metric means changing the job and backfilling from sources.

  • ELT approach: connectors load raw tables hourly into BigQuery; dbt models build orders_clean, daily_revenue and campaign_roi. A new metric is a new SQL model over data already stored.

Choosing Between Them

  • Choose ELT when you have a scalable cloud warehouse, want to keep raw history, and need analysts to iterate quickly.

  • Choose ETL when data must be filtered or anonymized before it leaves a secure zone, the target has limited compute, or transformations need non-SQL processing (images, complex parsing).

  • Many architectures are hybrid: light ETL (masking, format conversion) during ingestion, then ELT modelling in the warehouse.

Pitfalls

  • ELT cost surprises: inefficient SQL on huge raw tables can be expensive; use incremental models and partitioning.

  • Ungoverned raw data in ELT: restrict access to raw layers containing personal data.

  • ETL rigidity: business logic hidden in proprietary tool configurations that are hard to test or version.

Interview Tip

Explain the order of operations, why cloud warehouses made ELT popular, and when ETL is still the right choice (pre-load compliance). Mentioning dbt and incremental models shows practical experience.

43

How is big data processing handled in software architecture?

Big data processing is handled by distributing both storage and computation across clusters: data is stored in partitioned, replicated systems (object storage, distributed file systems, distributed databases), and processed in parallel by engines such as Apache Spark (batch), Apache Flink or Kafka Streams (streaming) and distributed SQL engines (Trino, BigQuery, Snowflake). Architectures combine ingestion, storage, processing, serving and governance layers, usually in a lake or lakehouse design.

Read full answer

Applies tomodern data platforms (Kafka, Spark, Flink, object storage with Parquet and Iceberg/Delta, cloud warehouses)

The Core Principles

  • Partitioning: split data (by date, customer, key) so many machines work on different parts at once.

  • Move compute to data: process data where it is stored to avoid shipping terabytes over the network.

  • Horizontal scaling: add nodes instead of buying bigger machines.

  • Fault tolerance: replicated storage and engines that retry failed tasks or restore from checkpoints.

  • Columnar formats (Parquet, ORC): read only the needed columns, with compression, which speeds analytical queries greatly.

Typical Layers

  1. Ingestion

  2. Batch: file drops, database exports, API pulls.

  3. Streaming: Kafka or a managed event stream, with change data capture (Debezium) from operational databases.

  4. Storage

  5. Data lake on object storage (raw and curated zones), open table formats for ACID tables.

  6. Warehouses for modelled analytical data.

  7. Processing

  8. Batch with Spark or warehouse SQL (dbt) for daily aggregates and ML features.

  9. Stream processing with Flink or Kafka Streams for real-time metrics, fraud detection and alerting.

  10. Serving

  11. BI dashboards, ad-hoc SQL, ML model training and feature stores, low-latency stores (Cassandra, Redis, Elasticsearch) for application queries.

  12. Orchestration and governance

  13. Airflow, Dagster or Prefect for scheduling pipelines; data catalogues, lineage, quality checks and access control.

Lambda vs Kappa Architecture

Pattern Idea Trade-off
Lambda Separate batch layer (accurate, slow) and speed layer (fast, approximate), merged at serving time Two code paths to maintain
Kappa One streaming pipeline; reprocess history by replaying the log Simpler code; needs a replayable log and strong stream processing

Many current platforms are closer to Kappa or a lakehouse with both batch and streaming reading the same tables.

Example

A ride-hailing company:

  • Trip events stream through Kafka.

  • Flink computes live surge pricing per zone every few seconds.

  • Raw events land in the lake as Parquet partitioned by date and city.

  • Nightly Spark jobs build driver earnings and demand forecasts.

  • Analysts query curated tables in a warehouse; ML teams train ETA models on the same data.

Key Challenges

  • Data skew: one hot key (a huge city) overloads one worker; salt keys or repartition.

  • Small files and poor partitioning that slow queries.

  • Late and out-of-order events in streaming; use event time and watermarks.

  • Exactly-once results: idempotent sinks or transactional writes.

  • Cost: large clusters and scans are expensive; use partition pruning, autoscaling and spot instances.

  • Governance and privacy at scale.

Interview Tip

Describe the layers (ingest, store, process, serve, govern), batch vs streaming, and the principles of partitioning and parallelism. A strong answer names concrete tools as examples and discusses skew or late data as real-world problems.

44

What role do message brokers play in system integration?

A message broker is middleware that receives, stores and routes messages between applications, so they can communicate asynchronously without knowing about each other. In system integration, brokers decouple producers from consumers in time and location, buffer load spikes, distribute work across consumers, fan out events to many systems, and translate or route messages between different applications.

Read full answer

Applies tointegration architecture (examples: RabbitMQ, Apache Kafka, ActiveMQ / Artemis, Amazon SQS and SNS, Azure Service Bus, Google Cloud Pub/Sub, NATS)

Integration Roles

  • Decoupling: an order system publishes OrderPlaced; billing, warehouse and CRM systems consume it without the order system calling each of them.

  • Temporal decoupling: if the warehouse system is down for maintenance, messages wait in its queue.

  • Load levelling: a flash sale generates 20,000 orders in a minute; consumers process them at a steady rate.

  • Work distribution: several workers share a queue (competing consumers).

  • Fan-out: publish-subscribe topics deliver one event to many subscribers.

  • Routing: RabbitMQ exchanges route by key or headers; Azure Service Bus subscriptions use filters.

  • Reliability: persistent messages, acknowledgements, retries and dead-letter queues.

  • Protocol bridging: AMQP, MQTT, STOMP and HTTP clients can share one broker.

Messaging Styles

Style Description Example
Point-to-point queue Each message processed by one consumer Invoice PDF generation jobs
Publish-subscribe Each subscriber gets every message CustomerUpdated to CRM, email and analytics
Request-reply Reply sent to a reply queue with a correlation ID Legacy systems needing asynchronous RPC
Event streaming (log) Ordered, retained log that consumers replay Kafka topics for event sourcing and analytics

Queue Broker vs Log Broker

Aspect Queue-based (RabbitMQ, SQS) Log-based (Kafka, Pulsar)
After consumption Message removed once acknowledged Retained for a configured period
Replay Not usually Yes, by resetting offsets
Routing Rich (exchanges, filters) Topic and partition
Ordering Per queue, weaker with many consumers Per partition
Best for Task queues, complex routing High-throughput event streams, multiple independent consumers

Design Considerations

  • Delivery guarantees: usually at-least-once, so consumers must be idempotent (deduplicate by message ID).

  • Ordering: use partition keys or single-consumer queues where order matters.

  • Poison messages: limited retries with backoff, then a dead-letter queue with alerts.

  • Schemas and versioning: Avro, Protobuf or JSON Schema with a registry; evolve compatibly.

  • Reliable publishing: the transactional outbox pattern avoids losing events when a database commit succeeds but the publish fails.

  • Security: TLS, authentication and per-topic permissions.

  • Monitoring: queue depth, consumer lag, dead-letter counts.

Trade-offs

  • The broker is critical infrastructure and must be clustered and replicated.

  • Eventual consistency between systems.

  • Harder debugging; use correlation IDs and tracing.

  • Not suited to requests that need an immediate answer (a user waiting for a search result).

Interview Tip

Explain decoupling, buffering and fan-out with an example, compare queues and logs, and mention idempotency, dead-letter queues and the outbox pattern. Those reliability details are what interviewers look for.

45

What is an API gateway and why is it important?

An API gateway is a single entry point that sits between clients and back-end services. It routes requests to the right service and centrally handles cross-cutting concerns: authentication, rate limiting, TLS termination, request and response transformation, caching, logging and metrics. It matters because it gives clients one stable API while hiding the internal structure of many services, and keeps security and traffic policies consistent.

Read full answer

Applies togeneral API architecture (examples: Kong, Apigee, AWS API Gateway, Azure API Management, Envoy-based gateways, NGINX, Spring Cloud Gateway)

Request Flow

Client → API gateway → (auth, rate limit, routing) → Orders / Catalog / Payments services

Core Functions

Function What it does
Routing /orders/* to the orders service, /catalog/* to catalog
Authentication Validates tokens (OAuth 2.0 / OpenID Connect, API keys) before requests reach services
Authorization (coarse) Checks scopes or plans; fine-grained rules stay in services
Rate limiting and quotas Per client or API key, returning 429 Too Many Requests
TLS termination Manages certificates at one place
Transformation Header changes, protocol translation (REST to gRPC), version mapping
Aggregation Combines several service calls into one response (often in a BFF)
Caching Caches public GET responses
Observability Access logs, metrics, trace IDs for every request
Developer portal API documentation, keys and usage plans (in API management products)

Why It Is Important

  • Simpler clients: one domain and one auth scheme instead of knowing many service addresses.

  • Security at the edge: unauthenticated and abusive traffic is stopped before reaching services.

  • Consistency: policies are applied the same way to every API.

  • Decoupling: services can be split, merged or moved without changing client URLs.

  • Versioning and gradual migration: route /v1 to a legacy system and /v2 to new services (strangler fig pattern).

  • Monetization and partner APIs: keys, quotas and analytics per consumer.

Backend for Frontend (BFF)

Instead of one gateway for every client, a BFF gives each client type (web, mobile, partners) its own gateway layer that shapes responses to that client’s needs. It avoids one gateway becoming bloated with client-specific logic.

API Gateway vs Service Mesh vs Load Balancer

Component Main focus
Load balancer Distributes traffic across instances (L4/L7)
API gateway North-south traffic: external clients to services, API policies
Service mesh East-west traffic: service-to-service mTLS, retries, telemetry

Pitfalls

  • Business logic in the gateway: it becomes a hidden monolith that every team must change. Keep it to cross-cutting concerns.

  • Single point of failure: run it redundantly across zones.

  • Added latency: each hop adds some milliseconds; keep plugins efficient.

  • Over-aggregation: gateway code calling many services becomes a fragile orchestrator.

  • Relying only on the gateway for security: services should still verify identity and authorization (zero trust).

Interview Tip

List the core functions, explain why centralizing them helps, and name the risks (bottleneck, business logic creep). Mentioning BFFs and the gateway vs service mesh distinction usually impresses interviewers.

46

How is Event Sourcing applied in software architecture?

Event Sourcing is applied by storing every change to an entity as an immutable event in an append-only event store, and deriving current state by replaying those events. In an architecture it is usually used for selected domains (such as orders, accounts or inventory) together with CQRS: the event store handles writes, and projections build read models for queries, while the same events drive integration with other services.

Read full answer

Applies toarchitecture pattern (examples: EventStoreDB, Axon Framework, Akka/Pekko Persistence, Marten for PostgreSQL, custom event tables)

How It Is Applied

  1. Model commands and events: PlaceOrder (a request) leads to OrderPlaced (a fact). Events use business language and past tense.

  2. Aggregates enforce rules: load the aggregate by replaying its events (or from a snapshot), validate the command, then append new events.

  3. Optimistic concurrency: append with an expected version; if another writer added events first, retry or reject.

  4. Projections: subscribers read the event stream and update read models (a SQL table for order lists, a search index, a cache).

  5. Integration: publish events (or translated integration events) to a broker so other services react.

  6. Snapshots: periodically store aggregate state so long streams do not have to be fully replayed.

Flow: Command → Aggregate (replay events) → Append to event store → Projections → Read models / other services

Example: Bank Account

Events for account A-17:

  1. AccountOpened(owner: Asha)

  2. MoneyDeposited(5000)

  3. MoneyWithdrawn(1200)

  4. MoneyDeposited(300)

Current balance = 4,100, computed from events. A statement projection lists transactions; a fraud service reacts to MoneyWithdrawn; an auditor can see exactly what happened and when.

Where It Fits

  • Audit-critical domains: finance, healthcare, compliance-heavy workflows.

  • Complex, collaborative domains where the history of changes matters (logistics, order lifecycles).

  • Temporal queries: “what was the state at month end?”

  • Rebuilding or adding read models later from the full history.

  • Event-driven architectures that already exchange domain events.

Where It Does Not

  • Simple CRUD data with no business need for history.

  • Teams without experience in eventual consistency and event versioning.

  • Data that must be fully deleted on request, unless designed for it (crypto-shredding, personal data kept outside events).

Trade-offs

Benefit Cost
Complete audit trail and history More complex than CRUD
Rebuildable read models Read models are eventually consistent
Natural integration via events Event schemas are permanent contracts; need versioning and upcasting
Append-only writes, low contention Replays and projections need operational care

Practical Tips

  • Apply it per bounded context, not to the whole system.

  • Keep internal domain events separate from public integration events, so internal changes do not break consumers.

  • Make projections idempotent and track their position in the stream.

  • Plan event versioning from day one.

  • Monitor projection lag.

Interview Tip

Explain commands, events, aggregates, projections and snapshots, then say where you would and would not use it. A common mistake is treating Event Sourcing and event-driven messaging as the same thing; one is a storage model, the other a communication style.

47

What are the strategies for managing database schema migrations?

Database schema migrations are managed by keeping every schema change as versioned, ordered migration scripts in source control, applying them automatically in each environment through the deployment pipeline, and designing changes to be backward compatible so old and new application versions can run at the same time. Large or risky changes use the expand-and-contract pattern, online schema change tools and tested rollback or roll-forward plans.

Read full answer

Applies togeneral practice with tools such as Flyway, Liquibase, Rails/Active Record migrations, Django migrations, Alembic, Entity Framework migrations, and online tools such as gh-ost and pt-online-schema-change

Core Practices

  • Migrations as code: each change is a numbered or timestamped file reviewed in pull requests.

  • Never edit an applied migration; add a new one.

  • A migrations table records which versions ran, so every environment converges to the same schema.

  • Automate: run migrations in CI against a fresh database and as part of deployment.

  • Same path everywhere: dev, staging and production run identical scripts.

Backward-Compatible Changes

During a rolling or blue-green deployment, old and new code run together, so each migration must work with both.

Safe in one step Needs expand-and-contract
Add a nullable column Rename a column or table
Add a new table Change a column type
Add an index (concurrently) Make a column NOT NULL
Add a column with a safe default (on databases that do this without rewriting the table) Drop a column still read by running code

Expand and Contract (Parallel Change)

Example: rename users.fullname to users.display_name.

  1. Expand: add display_name; deploy code that writes both columns.

  2. Backfill: copy existing values in batches.

  3. Migrate reads: deploy code that reads display_name.

  4. Contract: after all old code is gone, stop writing fullname and drop it in a later release.

Large Tables

  • Create indexes without blocking writes: CREATE INDEX CONCURRENTLY in PostgreSQL; online DDL in MySQL.

  • Backfill in small batches with pauses to avoid long locks and replication lag.

  • Online schema change tools (gh-ost, pt-online-schema-change) copy the table in the background and swap it in.

  • Set lock and statement timeouts so a migration fails fast instead of blocking traffic.

Rollback Strategy

  • Prefer roll-forward: fix with a new migration rather than reversing.

  • Write down migrations only where they are safe; dropping a column cannot be undone without a backup.

  • Back up (or ensure point-in-time recovery) before destructive changes.

  • Separate schema changes from code changes in time, so a code rollback does not need a schema rollback.

Data Migrations

  • Keep large data transformations separate from schema migrations, often as background jobs.

  • Make them idempotent and resumable.

  • Verify results with counts and checksums.

Multi-Service and Multi-Tenant Systems

  • Each service owns its schema and migrations; no service migrates another’s tables.

  • For schema-per-tenant or database-per-tenant designs, run migrations tenant by tenant with progress tracking and the ability to resume.

Pitfalls

  • Long-running migrations that lock tables during peak traffic.

  • Destructive changes deployed together with the code that stops using the column.

  • Environment drift from manual changes in production.

  • ORMs that auto-migrate on application startup in production, racing between instances.

Interview Tip

Explain versioned migrations, backward compatibility during deployments, and expand-and-contract with a rename example. Interviewers often ask how to add a NOT NULL column to a large table without downtime: add it nullable, backfill in batches, then add the constraint.

48

What are best practices for data consistency in distributed systems?

Data consistency in distributed systems is managed by choosing the consistency level each piece of data really needs, keeping strong consistency inside a single owner (one service, one database, one aggregate), and using eventual consistency with reliable patterns between services: the transactional outbox, idempotent consumers, sagas with compensations, versioning and optimistic concurrency, and reconciliation jobs to detect and repair drift.

Read full answer

Applies todistributed-systems architecture (microservices, replicated databases, event-driven systems)

1. Decide the Consistency Requirements

Data Typical requirement Why
Account balance, payments Strong Money must not be created or lost
Seat or stock reservation Strong at the reservation point Avoid double booking
Order history page Eventual (seconds) Slight delay is acceptable
Likes, view counts Eventual Approximate is fine
Search index Eventual Rebuilt from source of truth

Consistency models range from linearizable to causal, read-your-writes and eventual; choose per use case, not per system.

2. Single Source of Truth per Data Item

Each piece of data has one owning service and database. Others keep read-only copies updated from events. Avoid two services writing the same table.

3. Strong Consistency Where It Matters

  • Local ACID transactions inside the owning database.

  • Optimistic concurrency (version numbers or ETags) to prevent lost updates.

  • Consensus-based stores (etcd, Spanner, CockroachDB) when strongly consistent data must be replicated across nodes or regions, accepting the latency cost.

4. Reliable Event Publishing

The dual-write problem: saving to the database and publishing to a broker are two operations; one can fail.

  • Transactional outbox: write the change and an outbox row in the same transaction; a relay publishes outbox rows.

  • Change data capture (Debezium) reading the database log.

5. Idempotency and Ordering

  • Delivery is usually at-least-once, so consumers store processed message IDs or use idempotent upserts.

  • Use idempotency keys for client retries (for example on payment APIs).

  • Preserve order per entity with partition keys and version numbers; ignore events older than the current version.

6. Sagas Instead of Distributed Transactions

Two-phase commit across services blocks and reduces availability. A saga runs local transactions in sequence with compensating actions:

  1. Orders: create order (pending).

  2. Payments: charge card.

  3. Inventory: reserve stock; on failure, publish ReservationFailed.

  4. Compensate: refund the payment and cancel the order.

Choose orchestration (a coordinator drives the steps) or choreography (services react to each other’s events).

7. Handle Replication Lag

  • Route read-your-writes requests to the primary, or wait for a replica to catch up to a known position.

  • Show users the result of their own action immediately (optimistic UI) while the rest of the system converges.

8. Detect and Repair

  • Reconciliation jobs compare systems (payments vs orders) and fix or flag mismatches.

  • Monitoring of consumer lag and dead-letter queues.

  • Audit trails to trace how inconsistencies arose.

Common Mistakes

  • Assuming the network or broker never fails between a database write and a publish.

  • Distributed transactions across many services, hurting availability.

  • Non-idempotent consumers that double-apply events.

  • Treating eventual consistency as “no consistency” without defining how and when data converges.

Interview Tip

Start with “what consistency does this data need?”, then name the outbox, idempotency, sagas and reconciliation. Interviewers like a concrete saga example with a compensating action.

49

How do you secure integrations with third-party services?

Securing third-party integrations means treating every external service as untrusted: authenticate it strongly, give it the least privilege it needs, protect secrets, validate everything that comes back, verify inbound webhooks, encrypt traffic, and isolate the integration so a compromised or failing provider cannot take your system down or leak your data. It also includes vendor risk management: knowing what data you share and what the provider does with it.

Read full answer

Applies togeneral integration security (payment providers, SaaS APIs, OAuth logins, webhooks, SDKs and scripts)

Authentication and Authorization

  • Use OAuth 2.0 (client credentials for server-to-server, authorization code with PKCE for user-delegated access) where supported, rather than long-lived shared passwords.

  • Request the minimum scopes: read-only if you only read.

  • Prefer short-lived tokens; refresh them automatically.

  • Use mutual TLS or signed requests (for example HMAC signatures) for high-value server-to-server calls.

  • Separate credentials per environment and per integration so one leak has a limited blast radius.

Secrets Management

  • Store API keys and client secrets in a secrets manager (HashiCorp Vault, AWS Secrets Manager, Azure Key Vault), never in code, images or logs.

  • Rotate them regularly and immediately after staff changes or suspected exposure.

  • Restrict who and which services can read each secret.

  • Scan repositories for accidentally committed secrets.

Securing Inbound Webhooks

  • Verify signatures (for example an HMAC of the raw body with a shared secret) and reject unsigned requests.

  • Check a timestamp and reject old requests to prevent replays.

  • Make handlers idempotent: providers retry, so the same event may arrive twice.

  • Do not trust the payload alone for critical actions; where it matters, fetch the object back from the provider’s API to confirm its state (for example, that a payment really succeeded).

  • Respond quickly and process asynchronously.

Treat Responses as Untrusted Input

  • Validate schemas, types and sizes of responses.

  • Encode data before displaying it to avoid injected scripts.

  • Never pass provider data directly into SQL, shell commands or file paths.

  • Guard against SSRF if your system fetches URLs a third party supplies.

Data Protection

  • Minimize data shared: send only the fields the provider needs; tokenize or pseudonymize where possible.

  • Encrypt in transit (TLS 1.2+ with certificate validation) and ensure the provider encrypts at rest.

  • Check data residency and privacy obligations (GDPR data processing agreements, PCI DSS for card data).

  • For payments, use hosted fields or redirects so card data never touches your servers, reducing PCI scope.

Isolation and Resilience

  • Wrap each provider in an adapter or anti-corruption layer, so provider changes stay local.

  • Use timeouts, retries with backoff and circuit breakers; a slow provider must not exhaust your threads.

  • Run integrations from separate network zones with egress allowlists for known provider domains.

  • Pin and review third-party SDKs and front-end scripts; use Subresource Integrity and a Content Security Policy for browser scripts.

Monitoring and Vendor Management

  • Log calls (without secrets or personal data), monitor error rates, unusual volumes and permission changes.

  • Assess vendors: security certifications (SOC 2, ISO 27001), breach history, incident notification terms.

  • Keep an inventory of integrations, their data, owners and credentials, and remove unused ones.

  • Have an exit and incident plan: how to revoke access and switch provider quickly.

Interview Tip

Organize the answer as authentication, secrets, inbound webhooks, untrusted responses, data minimization and resilience. Mentioning webhook signature verification, least-privilege scopes and supply-chain risk from SDKs shows real-world experience.

50

SQL vs NoSQL: how do you choose for a system?

Choose based on data shape, query patterns, consistency needs and scale, not fashion. SQL (relational) databases suit structured, related data that needs joins, ACID transactions, constraints and flexible ad-hoc queries. NoSQL databases (document, key-value, wide-column, graph) suit specific access patterns at large scale, flexible or nested schemas, very high write throughput, or relationship-heavy data. For most new business applications a relational database is the safer default; add NoSQL where a clear need appears.

Read full answer

Applies todatabase selection (relational: PostgreSQL, MySQL, SQL Server, Oracle; NoSQL: MongoDB, DynamoDB, Cassandra, Redis, Neo4j)

Comparison

Aspect SQL NoSQL
Data model Tables, rows, foreign keys Documents, key-value, wide-column, graph
Schema Defined up front, enforced Flexible; enforced by the application (often optional validation)
Queries Rich SQL, joins, aggregation, ad-hoc Optimized for known access patterns; joins limited or absent (graph DBs excel at traversals)
Transactions Multi-row ACID by default Varies: single-item atomicity common; many now offer multi-document transactions
Scaling Vertical first; read replicas; sharding is harder Designed for horizontal partitioning
Consistency Strong by default Ranges from strong to eventual, often tunable

Questions to Ask

  1. What do queries look like? Many ad-hoc reports and joins point to SQL. A few predictable lookups by key at huge volume point to key-value or wide-column.

  2. How related is the data? Orders, customers, invoices with integrity rules: relational. Deep, many-hop relationships (social graphs, fraud rings): graph.

  3. What consistency is required? Financial balances need strong transactions. Activity feeds tolerate eventual consistency.

  4. What scale? A single PostgreSQL instance handles a large amount of traffic for many applications; tens of thousands of writes per second or multi-region active-active writes may justify Cassandra or DynamoDB.

  5. How stable is the schema? Highly variable attributes (product catalogues with different fields per category) suit documents, or JSON columns in a relational database.

  6. Team skills and operations: managed services and familiarity reduce risk.

Matching Use Cases

Use case Good fit
Banking ledger, ERP, e-commerce orders Relational
Product catalogue with varied attributes Document store, or PostgreSQL JSONB
Session store, caching, rate-limit counters Key-value (Redis)
IoT telemetry, time series, write-heavy logs Wide-column (Cassandra) or time-series DB
Recommendations, social graph Graph database
Shopping cart at massive scale with simple access Key-value (DynamoDB)

Polyglot Persistence

Large systems often use several stores: PostgreSQL as the system of record for orders, Redis for sessions, Elasticsearch for search and a warehouse for analytics. The trade-off is operational complexity and data synchronization (usually via events or change data capture).

Common Mistakes

  • Choosing NoSQL “for scale” before having a scale problem, then reimplementing joins and transactions in application code.

  • Modelling NoSQL like relational tables; NoSQL data should be designed around queries.

  • Ignoring that relational databases also scale: replicas, partitioning, and distributed SQL databases (CockroachDB, Spanner, YugabyteDB).

  • No plan for changing access patterns: a key-value design can make new queries expensive.

Interview Tip

Do not give a blanket answer. Walk through access patterns, relationships, consistency and scale, then pick per data set. Saying “PostgreSQL by default, with specific NoSQL stores where requirements demand them” and justifying it is a strong answer.

51

How do you design a fault-tolerant system?

A fault-tolerant system keeps working, possibly in a degraded mode, when components fail. You design it by assuming failures will happen and adding redundancy (no single point of failure), isolation (failures stay contained), detection and automatic recovery (health checks, failover, self-healing), resilient communication (timeouts, retries, circuit breakers), and durable, replicated data, then testing it with failure drills and chaos experiments.

Read full answer

Applies togeneral system architecture (cloud and on-premises)

1. Remove Single Points of Failure

  • Run multiple instances of every stateless service behind a load balancer.

  • Spread them across availability zones; for critical systems, across regions.

  • Replicate databases (primary with synchronous or semi-synchronous replicas, or a consensus-based cluster).

  • Duplicate network paths, DNS providers where justified, and power in data centres.

2. Isolate Failures

  • Bulkheads: separate thread pools, connection pools or even clusters per dependency or customer tier, so one overloaded dependency cannot consume everything.

  • Cell-based architecture: split users into independent cells, so a failure affects only a fraction.

  • Asynchronous queues between components so a slow consumer does not block producers.

3. Resilient Communication

  • Timeouts on every remote call.

  • Retries with exponential backoff and jitter, only for idempotent operations, with a retry budget.

  • Circuit breakers to stop calling a failing dependency and fail fast.

  • Idempotency keys so retries do not duplicate effects.

  • Fallbacks: cached data, default values or reduced functionality.

4. Detect and Recover Automatically

  • Health checks (liveness and readiness) so orchestrators restart unhealthy instances and stop routing to them.

  • Automatic failover for databases and services, with fencing to avoid split-brain.

  • Auto-scaling to replace lost capacity.

  • Immutable infrastructure so a broken node is replaced, not repaired.

5. Protect the Data

  • Replication for availability, backups and point-in-time recovery for corruption or deletion (replication copies mistakes too).

  • Define RPO (acceptable data loss) and RTO (acceptable downtime) and design to them.

  • Use quorum writes or consensus where losing acknowledged writes is unacceptable.

6. Degrade Gracefully and Shed Load

  • Disable non-essential features (recommendations, analytics) to keep core flows (checkout, login) working.

  • Rate limiting and load shedding to protect the system from overload; reject some requests quickly rather than failing all slowly.

7. Test Failures

  • Chaos engineering: deliberately kill instances, inject latency, fail a zone in a controlled way.

  • Game days and disaster-recovery drills to practise regional failover.

  • Verify that alerts fire and runbooks work.

Example

An online payment API:

  • Stateless API servers in three zones behind a load balancer.

  • A PostgreSQL cluster with a synchronous standby in another zone and automatic failover.

  • Calls to the card processor with 2-second timeouts, a circuit breaker and a queue for retrying settlement.

  • Idempotency keys on every payment request.

  • If the fraud-scoring service is down, low-value payments proceed with basic rules; high-value ones are queued for review.

Trade-offs

  • Cost: redundancy multiplies infrastructure.

  • Complexity: more moving parts and failure modes (split-brain, retry storms).

  • Consistency vs availability during partitions.

  • Latency: synchronous cross-zone replication adds milliseconds per write.

Interview Tip

Structure the answer as redundancy, isolation, resilient calls, detection and recovery, data protection, graceful degradation and testing. Mention RPO/RTO and that replication is not a backup; interviewers often check for both.

52

What practices make a software system maintainable?

A maintainable system is one that people can understand, change, test and operate safely over years. The key practices are clear modular structure with low coupling and high cohesion, readable, consistent code, automated tests, CI/CD with small, frequent changes, good documentation of decisions, observability, managed dependencies, and a culture of continuous refactoring and paying down technical debt.

Read full answer

Applies togeneral software engineering and architecture

Structural Practices

  • Modularity: organize code by business capability (modules or bounded contexts) with clear interfaces.

  • Low coupling, high cohesion: modules depend on few others and contain closely related logic.

  • Separation of concerns: business rules separate from frameworks, UI and infrastructure (layered, hexagonal or clean architecture).

  • Explicit dependencies and enforced boundaries (architecture tests, module rules) so structure does not erode.

  • Simple designs over clever ones (YAGNI): add abstractions when a real need appears.

Code-Level Practices

  • Consistent style enforced by formatters and linters.

  • Meaningful names and small functions with a single responsibility.

  • Avoid duplication of business rules, but do not merge unrelated code just because it looks similar.

  • Code reviews focused on clarity, design and tests.

  • Handle errors explicitly and log useful context.

Testing and Delivery

  • A test pyramid: many fast unit tests, fewer integration tests, a small number of end-to-end tests.

  • Tests that describe behaviour, so refactoring does not break them unnecessarily.

  • Continuous integration on every change; continuous delivery with small releases that are easy to roll back.

  • Feature flags to separate deployment from release.

Knowledge and Documentation

  • A README that explains setup, running and testing.

  • Architecture Decision Records (ADRs) explaining why choices were made.

  • Architecture diagrams (for example C4 context and container diagrams) kept current.

  • API contracts (OpenAPI, protobuf) as the source of truth for interfaces.

  • Runbooks for operations and incidents.

Operational Maintainability

  • Observability: structured logs, metrics and traces, so problems can be diagnosed without guesswork.

  • Configuration outside code, consistent across environments.

  • Infrastructure as code so environments are reproducible.

Dependency and Debt Management

  • Regular dependency updates (automated tools such as Dependabot or Renovate) instead of large, risky upgrades every few years.

  • Remove dead code and unused features.

  • Track technical debt explicitly and reserve capacity to address it.

  • Boy Scout rule: leave code a little better than you found it.

Measuring Maintainability

  • Change lead time and change failure rate (DORA metrics).

  • Code hotspots: files that change often and have high complexity.

  • Time for a new developer to make a first meaningful change.

  • Test coverage of critical paths (as a signal, not a target).

Trade-offs

Maintainability practices cost time up front. For a short-lived prototype, heavy structure and documentation may not pay off; for a long-lived core system, skipping them makes every future change slower and riskier.

Interview Tip

Cover structure, code quality, tests, delivery, documentation and observability, and give a concrete example (for example, introducing module boundaries or ADRs). Mentioning how you would measure maintainability, such as lead time and hotspots, is a strong differentiator.

53

How should software architecture be documented?

Software architecture should be documented just enough to explain the system’s structure and the reasons behind it, aimed at specific audiences, and kept close to the code so it stays current. Effective documentation usually combines diagrams at several levels of detail (such as the C4 model), Architecture Decision Records (ADRs) for key choices, quality attribute requirements, interface contracts, and operational runbooks, all stored in version control and reviewed like code.

Read full answer

Applies toarchitecture practice (C4 model, arc42 template, ADRs, docs-as-code with Markdown, Structurizr, PlantUML, Mermaid)

What to Document

Item Purpose
Context and goals What the system does, for whom, key business drivers
Quality attributes Measurable targets: availability, latency, security, scalability
Constraints Regulations, mandated technologies, budgets, team structure
Structural views Diagrams of systems, containers, components, deployment
Key decisions ADRs: context, options, decision, consequences
Interfaces API contracts (OpenAPI, AsyncAPI, protobuf), event schemas
Cross-cutting concepts Security model, error handling, logging, data ownership
Risks and technical debt Known issues and planned mitigations
Operations Deployment, monitoring, runbooks, disaster recovery

The C4 Model for Diagrams

  1. Context: the system, its users and external systems.

  2. Containers: deployable units (web app, API, database, message broker) and how they communicate.

  3. Components: major parts inside a container.

  4. Code: classes, usually generated or skipped.

Most teams maintain levels 1 and 2 carefully, level 3 for complex containers only. Add deployment diagrams and sequence diagrams for important flows.

Architecture Decision Records

Short documents, one per significant decision, for example:

  • Title: ADR-012 Use PostgreSQL for order data.

  • Status: Accepted.

  • Context: transactional data, strong consistency, team experience.

  • Options considered: PostgreSQL, MongoDB, DynamoDB.

  • Decision and rationale.

  • Consequences: positive and negative.

ADRs are never edited to reverse a decision; a new ADR supersedes the old one, preserving history.

Keeping It Current

  • Docs as code: Markdown and diagram-as-code files in the repository, updated in the same pull request as the change.

  • Generate what can be generated: API references from OpenAPI, dependency graphs from code, infrastructure diagrams from IaC.

  • Review documentation in architecture reviews and code reviews.

  • Date and own each document so readers know whether to trust it.

  • Delete documentation that is no longer true.

Tailor to Audiences

Audience Needs
Executives and product managers Context diagram, goals, risks, costs
New developers Container and component views, setup, conventions
Operations / SRE Deployment view, dependencies, runbooks, SLOs
Security and compliance Data flows, trust boundaries, controls
Partner teams API contracts, events, SLAs

Pitfalls

  • Big up-front documents that are out of date within weeks.

  • Diagrams with no legend or mixed abstraction levels (servers and classes on the same picture).

  • Documenting what but not why; the why is what future maintainers most need.

  • Hidden documentation in wikis nobody can find.

Interview Tip

Mention C4 for diagrams, ADRs for decisions, and docs-as-code to keep them current. Emphasizing “just enough, per audience, focused on why” shows a pragmatic architect rather than someone producing paperwork.

54

How do you manage technical debt in architecture?

Technical debt is managed by making it visible, measured and prioritized like any other work: identify and record debt items, assess their impact (interest) and cost to fix, agree with product stakeholders on a steady investment (for example a fixed share of each sprint), fix debt close to the features that touch it, and prevent new unintended debt through architecture guidelines, reviews and automated checks. The goal is not zero debt but controlled debt that does not slow delivery.

Read full answer

Applies toarchitecture and engineering management practice

Types of Technical Debt

  • Deliberate: shortcuts taken knowingly to meet a deadline (with a plan to repay).

  • Accidental: design that seemed right but no longer fits.

  • Bit rot: outdated dependencies, frameworks and platforms.

  • Architectural debt: tangled modules, a shared database between services, missing boundaries. This is the most expensive kind because it affects many teams.

1. Make It Visible

  • Keep a technical debt register (backlog items or ADRs) describing each item, its impact and owner.

  • Use code analysis: hotspots (files with high complexity that change frequently), cyclic dependencies, outdated libraries.

  • Collect developer feedback: what slows you down most?

  • Track symptoms: lead time, change failure rate, incident causes, onboarding time.

2. Assess and Prioritize

Score items by:

Factor Question
Interest How much does this slow us or risk incidents today?
Principal How much effort to fix?
Exposure How often is this code changed?
Risk Security, compliance or end-of-life deadlines?

High-interest, frequently changed areas come first. Debt in code that nobody touches may be left alone.

3. Pay It Down Strategically

  • Budget: dedicate a share of capacity (commonly 10–20%) to debt and platform work.

  • Fix as you go: refactor the parts a feature touches (Boy Scout rule).

  • Larger efforts as projects with business justification: for example, splitting a shared database before scaling the team.

  • Incremental migrations (strangler fig pattern, branch by abstraction) rather than big rewrites, which are risky and often fail.

  • Retire unused features and code.

4. Communicate in Business Terms

Explain debt as cost and risk: “Every change to pricing takes three weeks because of the shared module; separating it would cut that to days” is more persuasive than “the code is messy”. Link debt work to goals: faster delivery, fewer incidents, compliance deadlines.

5. Prevent Unintended Debt

  • Architecture principles and ADRs so decisions are deliberate and documented.

  • Fitness functions and automated checks: dependency rules, performance budgets, dependency update bots.

  • Code reviews and design reviews for significant changes.

  • Definition of done that includes tests and documentation.

  • Record deliberate shortcuts with an explicit repayment plan.

Example

A team finds that 40% of incidents come from a legacy billing module with no tests. They:

  1. Add characterization tests around it.

  2. Extract a clean billing interface.

  3. Move new pricing rules behind the interface.

  4. Gradually migrate old rules over three quarters using 15% of capacity.

Incidents from billing drop, and new pricing features ship faster.

Pitfalls

  • Hidden debt: never discussed, so it grows until a crisis.

  • “Debt sprints” only: one-off cleanups that do not change habits.

  • Big-bang rewrites that stall feature delivery for months.

  • Treating all debt as equal instead of prioritizing by interest.

Interview Tip

Use the debt metaphor (principal and interest), explain visibility, prioritization and steady repayment, and give an example of explaining debt in business terms. Mentioning hotspot analysis and the strangler fig pattern shows hands-on experience.

55

How does automated testing ensure system resilience?

Automated testing ensures resilience by repeatedly proving that the system behaves correctly not only on the happy path but also under failures, load and change. Beyond unit and integration tests, resilience comes from failure-path tests (timeouts, retries, fallbacks), contract tests between services, load and stress tests, chaos and fault-injection experiments, recovery tests (failover, backup restore) and post-deployment checks, all run automatically so regressions are caught before users notice.

Read full answer

Applies togeneral engineering practice (tools such as JUnit/pytest, Testcontainers, Pact, k6/Gatling/JMeter, Toxiproxy, Chaos Mesh, Litmus, AWS Fault Injection Service, Gremlin)

Layers of Testing for Resilience

Test type What it protects Example
Unit tests Logic, including error handling Retry policy stops after 3 attempts
Integration tests Behaviour with real dependencies Service handles database connection loss
Contract tests Compatibility between services Consumer still works after provider changes API
Fault injection tests Timeouts, errors, latency Payment client trips circuit breaker when provider is slow
Load and stress tests Capacity, saturation behaviour System sheds load at 3x peak instead of crashing
Soak tests Leaks and slow degradation Memory stable over 12 hours
Chaos experiments Real infrastructure failure Killing pods or a zone keeps the service available
Disaster-recovery tests Restore and failover Restoring last night’s backup meets RTO
Smoke and synthetic tests Production health after deploy Login and checkout journeys succeed

Testing Failure Paths

Many outages come from error-handling code that never ran before the incident. Automated tests should cover:

  • Timeouts and slow responses (inject latency with tools such as Toxiproxy or WireMock delays).

  • Error responses (500s, 429 rate limits, malformed data).

  • Retries with backoff, ensuring operations are idempotent.

  • Circuit breakers opening and closing.

  • Fallbacks: cached or default responses.

  • Partial failures in sagas and their compensating actions.

Chaos Engineering

  1. Define steady state (for example, 99.9% of checkout requests succeed under 500 ms).

  2. Hypothesize it holds when a failure occurs.

  3. Inject the failure (terminate instances, block a dependency, add network latency).

  4. Compare results; fix weaknesses found.

  5. Start in staging with a small blast radius, automate, and gradually run in production with safeguards.

Integrating Into the Pipeline

  • On every commit: unit, component and contract tests.

  • Before release: integration, fault injection, performance smoke tests.

  • Regularly scheduled: full load tests, soak tests, chaos experiments, backup restores.

  • After deployment: smoke tests and canary analysis with automatic rollback.

What Testing Does Not Guarantee

  • Tests cover known scenarios; production can fail in new ways, so combine testing with observability, alerts and incident reviews.

  • Test environments differ from production in scale and data; validate key assumptions in production carefully (canaries, controlled chaos).

  • Flaky tests reduce trust; fix or remove them.

Example

An e-commerce team adds a test that makes the recommendation service respond in 5 seconds. The test shows that product pages wait for it and time out. They add a 300 ms timeout with an empty-recommendations fallback; the test now passes, and a later real outage of that service goes unnoticed by customers.

Interview Tip

Emphasize testing failure paths, not just features, and mention contract tests, load tests, chaos engineering and restore drills. Explaining steady-state hypotheses and small blast radius shows you understand chaos engineering as a discipline, not random breakage.

56

What is the role of refactoring in software architecture?

Refactoring is changing the internal structure of software without changing its external behaviour, to make it easier to understand and modify. In architecture it is the main tool for keeping the design fit as requirements evolve: it removes accumulated technical debt, reinforces module boundaries, enables new capabilities (such as extracting a service), and lets architecture evolve incrementally and safely instead of through risky rewrites.

Read full answer

Applies togeneral architecture and engineering practice (code-level and architecture-level refactoring)

Code-Level vs Architecture-Level Refactoring

Level Examples Scope
Code Extract method, rename, remove duplication, simplify conditionals Minutes to hours, one developer
Design Introduce an interface, split a large class, apply a pattern Days, one team
Architecture Separate a module, break a shared database, extract a microservice, replace a framework Weeks to months, often several teams

Why It Matters Architecturally

  • Evolutionary architecture: requirements change, and the structure must follow. Refactoring keeps the architecture aligned with the domain.

  • Prevents erosion: without it, boundaries blur and the system becomes a tangled “big ball of mud”.

  • Enables change: features that were hard become easy after restructuring (for example, a separated pricing module allows rapid pricing experiments).

  • Reduces risk: small, tested steps are safer than big rewrites.

  • Improves quality attributes: performance, scalability and testability through better structure.

Techniques for Large-Scale Refactoring

  • Strangler fig pattern: route functionality gradually from the old system to the new one until the old system can be removed.

  • Branch by abstraction: put an interface in front of the old implementation, build the new one behind it, switch over, then delete the old one, all on the main branch.

  • Parallel change (expand and contract) for APIs and database schemas.

  • Feature flags to switch between old and new paths safely.

  • Modularize first: create clean module boundaries inside a monolith before extracting services.

Prerequisites for Safe Refactoring

  • Automated tests that describe behaviour; for legacy code, add characterization tests first.

  • Continuous integration so every small step is verified.

  • Small, frequent commits that keep the system working.

  • Observability to detect behaviour changes in production.

  • Architecture fitness functions to verify the target structure (for example, no module depends on billing internals).

When to Refactor

  • Continuously, as part of feature work (the Boy Scout rule).

  • Before a feature that the current structure makes hard (“make the change easy, then make the easy change”).

  • When hotspot analysis shows high-complexity code that changes often.

  • After incidents that reveal structural weaknesses.

Refactoring vs Rewriting

A rewrite replaces the system wholesale. It often takes longer than expected, freezes feature delivery and loses hidden business rules. Refactoring delivers value incrementally and keeps the system running. Rewrites are occasionally justified (unsupported platform, fundamentally wrong model) but are usually best done incrementally anyway with the strangler fig approach.

Pitfalls

  • Refactoring without tests, so behaviour changes go unnoticed.

  • Endless refactoring with no business goal; tie it to measurable outcomes.

  • Mixing refactoring with behaviour changes in one large change, making reviews and rollbacks hard.

  • Long-lived refactoring branches that conflict with ongoing work.

Interview Tip

Define refactoring precisely (structure changes, behaviour stays), then connect it to evolutionary architecture, the strangler fig and branch by abstraction. Contrasting it with a big-bang rewrite and stressing tests as a prerequisite makes a well-rounded answer.

57

What is graceful degradation and how do you design for it?

Graceful degradation means that when part of a system fails or is overloaded, the system keeps its core functions working with reduced quality instead of failing completely. You design for it by ranking features by criticality, making non-critical dependencies optional with fallbacks, using timeouts and circuit breakers, shedding load in a controlled way, and telling users clearly when something is limited.

Read full answer

Applies togeneral system and front-end architecture

Example

During a sale, an online shop’s recommendation service fails:

  • Without graceful degradation: product pages wait for recommendations, time out and return errors. Sales stop.

  • With graceful degradation: product pages show a static “popular items” list (or nothing) after a 200 ms timeout. Customers keep buying.

Design Steps

  1. Classify features

  2. Critical: login, browse, checkout, payment.

  3. Important: search filters, order tracking.

  4. Optional: recommendations, reviews, personalization, analytics.

  5. Map dependencies for each feature and identify which failures affect which features.

  6. Define a fallback for each non-critical dependency

  7. Cached or stale data (“prices as of 5 minutes ago” for display).

  8. Default values (generic recommendations).

  9. Hide the feature.

  10. Queue the work for later (send confirmation emails when the mail service returns).

  11. Implement protection

  12. Short timeouts on every call.

  13. Circuit breakers to fail fast and trigger fallbacks.

  14. Bulkheads so a slow dependency cannot exhaust shared thread or connection pools.

  15. Asynchronous processing for non-urgent work.

  16. Control overload

  17. Rate limiting and load shedding: reject low-priority requests early (with 429 or 503) to protect high-priority ones.

  18. Priority queues: checkout traffic before background reports.

  19. Feature flags / kill switches to turn off expensive features under load.

  20. Communicate: messages such as “Reviews are temporarily unavailable” rather than blank errors.

Front-End Degradation

  • Render core content server-side so pages work if some scripts fail.

  • Isolate widgets so one failing component does not break the whole page.

  • Offline-capable apps show cached data and queue user actions until the connection returns.

Data Consistency Considerations

Serving stale data must be acceptable for that feature. For example, showing cached product descriptions is fine, but final payment amounts must come from the authoritative service. Decide explicitly which data can be stale and for how long.

Testing Graceful Degradation

  • Fault-injection tests that disable each dependency and verify the fallback.

  • Load tests that confirm load shedding protects critical paths.

  • Chaos experiments and game days in staging or production.

  • Monitor fallback rates; frequent fallbacks indicate a hidden problem.

Trade-offs

Benefit Cost
Core business keeps running during failures Extra code paths to build and test
Better user experience than full outages Stale or reduced data may confuse users
Protects against cascading failures Fallbacks can hide failures if not monitored

Interview Tip

Give a concrete example, then explain classifying features, fallbacks, timeouts and circuit breakers, and load shedding. Mentioning that fallbacks must be tested and monitored shows maturity.

58

How do you ensure backward compatibility when evolving a system?

Backward compatibility means existing clients, data and integrations keep working after the system changes. You ensure it by preferring additive changes, following tolerant reader rules, versioning interfaces when breaking changes are unavoidable, using expand-and-contract migrations for data and APIs, checking compatibility automatically with contract tests and schema registries, and deprecating old behaviour gradually with clear timelines.

Read full answer

Applies toAPIs (REST, gRPC, GraphQL), event and message schemas, database schemas, libraries and SDKs

Compatible vs Breaking Changes

Usually compatible Usually breaking
Adding an optional field to a response Removing or renaming a field
Adding a new endpoint or event type Changing a field’s type or meaning
Adding an optional request parameter Making an optional parameter required
Adding a new enum value (if clients tolerate unknown values) Changing URL structure or error formats
Loosening validation Tightening validation

Key Techniques

  • Additive change first: add new fields alongside old ones rather than changing existing ones.

  • Tolerant reader: clients ignore unknown fields and handle unknown enum values with a default.

  • Robust defaults: new fields have sensible defaults for old clients and old data.

  • Expand and contract:

  • Add the new field or endpoint.

  • Migrate clients and data to it.

  • Remove the old one only after usage drops to zero.

  • Versioning for unavoidable breaks: URL (/v2/orders), header or media type versions for REST; new message types or package versions for gRPC; new topics or schema versions for events.

  • Adapters: translate old requests to the new model internally so only one core implementation exists.

Schema Evolution Rules

  • Protobuf: never reuse or renumber field tags; mark removed fields as reserved.

  • Avro / JSON Schema with a schema registry: enforce backward or full compatibility rules automatically when publishing new schemas.

  • Database schemas: support both old and new application versions during rolling deployments.

Automated Safeguards

  • Consumer-driven contract tests (such as Pact): providers verify that they still satisfy every consumer’s expectations.

  • Schema compatibility checks in CI (registry checks, OpenAPI diff tools such as oasdiff, buf breaking for protobuf).

  • Integration tests running old client versions against the new server.

Deprecation Process

  1. Announce deprecation with a timeline and migration guide.

  2. Mark it in documentation and responses (for example the Deprecation and Sunset HTTP headers).

  3. Monitor usage of old endpoints or fields per client.

  4. Contact remaining users before removal.

  5. Remove only after the sunset date and when usage is near zero.

Example

An orders API returns price as a number in dollars. The team wants currency support:

  • Add amount (in minor units) and currency fields while still returning price.

  • Update documentation and SDKs to use the new fields.

  • Track which clients still read price; after 12 months and outreach, remove it in /v2 or after the sunset date.

Trade-offs

  • Supporting old versions adds maintenance cost and complexity.

  • Too many parallel versions slow development; limit how many are supported at once.

  • Strict compatibility can slow necessary redesigns; versioning gives a clean path when needed.

Interview Tip

Classify compatible vs breaking changes, then explain additive change, tolerant readers, expand and contract, versioning and contract tests. Mentioning usage monitoring before removal shows you think about real consumers, not just the code.

59

How do you plan and execute feature deprecation?

Feature deprecation is planned by deciding based on usage and cost data, communicating early with a clear timeline and migration path, measuring who still uses the feature, reducing usage in stages (warnings, blocking new adoption, soft shutdown), and finally removing the code, data and infrastructure safely. The aim is to retire the feature without surprising users or breaking dependent systems.

Read full answer

Applies toproduct and platform engineering (UI features, APIs, SDK methods, configuration options, internal services)

1. Decide With Data

  • Usage: how many users or clients use it, how often, and which customers.

  • Cost: maintenance effort, infrastructure, security risk, complexity it adds to other features.

  • Alternatives: is there a replacement, and does it cover all real use cases?

  • Contracts: SLAs, regulatory or contractual obligations to keep it.

  • Record the decision and rationale (for example in an ADR or product decision record).

2. Prepare the Replacement and Migration

  • Ensure the replacement is ready and documented before announcing.

  • Write a migration guide with examples and, for APIs, mapping from old to new calls.

  • Provide tools or automatic migration where possible (data export, scripts, codemods).

3. Communicate

  • Announce through release notes, documentation, emails to affected users, in-app notices and dashboards for partners.

  • Give a timeline proportional to impact: weeks for minor UI features, often 6–12 months or longer for public APIs.

  • For APIs, add machine-readable signals: the Deprecation and Sunset response headers, deprecation flags in OpenAPI or SDK annotations (@Deprecated), compiler warnings.

4. Execute in Stages

Stage Action
Announce Public notice, docs updated, deprecation warnings
Freeze No new features; block new sign-ups or new API keys from using it
Migrate Support customers, track usage per account, contact heavy users directly
Brownouts (for APIs) Temporary planned outages to reveal forgotten dependencies
Disable Turn off behind a feature flag, ready to re-enable briefly if critical issues appear
Remove Delete code, tests, configuration, infrastructure and data per retention rules

5. Clean Up Properly

  • Remove dead code paths, feature flags and documentation.

  • Decommission infrastructure (queues, databases, cron jobs) and revoke credentials.

  • Handle data: migrate, archive or delete according to retention and privacy obligations.

  • Update monitoring and runbooks.

Example

A SaaS product replaces its legacy CSV export with a new reporting API:

  1. Usage data shows 300 accounts using CSV export monthly.

  2. The new API and a CSV download in the new reports UI are launched first.

  3. A 6-month deprecation is announced with a migration guide.

  4. New accounts no longer see the legacy export after month 1.

  5. Account managers contact the top 30 users.

  6. Two short brownouts in month 5 reveal an internal finance script still using it; it is migrated.

  7. The feature is disabled in month 6 and removed in month 7.

Pitfalls

  • Deprecating without a replacement that covers real use cases.

  • No usage tracking, so the team cannot tell who will break.

  • Announcing and then never removing, which teaches users to ignore deprecation notices.

  • Forgetting internal consumers such as scripts, reports and other services.

  • Leaving dead code and flags that keep adding complexity.

Interview Tip

Walk through data-driven decision, replacement first, communication, staged execution and cleanup. Mentioning brownouts and usage tracking per client shows experience with real deprecations.

60

What debugging strategies work for complex distributed systems?

Debugging distributed systems relies on observability rather than stepping through code: correlate distributed traces, structured logs and metrics using shared request or trace IDs, narrow the problem down systematically (which service, which dependency, which change), reproduce it with realistic conditions, and look specifically for distributed failure modes such as timeouts, retries, race conditions, partial failures, clock skew and inconsistent data.

Read full answer

Applies tomicroservices, event-driven and cloud systems (OpenTelemetry, Jaeger, Grafana Tempo, Zipkin, Prometheus, Grafana, Elasticsearch/OpenSearch, Loki, cloud-native tools)

1. Instrument Before Problems Happen

  • Distributed tracing (OpenTelemetry): each request gets a trace ID passed across HTTP, gRPC and message headers, showing every service hop and its duration.

  • Structured logs (JSON) with trace ID, request ID, user or tenant ID, service and version.

  • Metrics: request rate, errors and duration (RED) per service and endpoint; resource saturation (CPU, memory, connections, queue lag).

  • Events: deployments, configuration changes and feature-flag changes recorded on dashboards.

2. Systematic Investigation

  1. Define the symptom precisely: which users, endpoints, regions, error codes, since when?

  2. Check recent changes: deployments, flag changes, infrastructure updates, dependency releases. Many incidents correlate with a change.

  3. Find the failing component: use service maps and traces to locate where latency or errors originate, not just where they surface.

  4. Compare good and bad: requests that succeed vs fail; one zone vs another; old version vs new.

  5. Form hypotheses and test them one at a time with data.

  6. Mitigate first in production incidents (roll back, disable a flag, fail over), then find the root cause.

3. Common Distributed Failure Modes

Symptom Possible cause
Latency spikes across many services Shared dependency slow (database, DNS, cache), retry storms
Intermittent errors One bad instance, connection pool exhaustion, network issues
Duplicate actions At-least-once delivery without idempotency, client retries
Data mismatch between services Lost events, ordering issues, failed saga compensation
Works locally, fails in production Configuration differences, scale, timeouts, permissions
Events in “wrong” order in logs Clock skew; rely on trace spans or logical ordering instead
Gradual slowdown Memory leaks, growing queues, unbounded caches

4. Reproducing Problems

  • Recreate with production-like data and load in staging.

  • Use traffic replay or recorded requests.

  • Use fault injection (latency, dropped connections) to reproduce timing issues.

  • Run services locally with containers or connect to shared test environments.

  • For concurrency bugs, add targeted logging or deterministic testing tools.

5. Useful Techniques

  • Exemplars: link a slow metric data point directly to a trace.

  • Dynamic log levels: raise verbosity temporarily for one service or tenant.

  • Feature flags to isolate a suspect code path.

  • Canary analysis: compare metrics of new and old versions.

  • Profiling in production (continuous profilers) for CPU or memory issues.

  • Dead-letter queue inspection for message-processing failures.

After the Fix

  • Blameless postmortem: timeline, root causes, contributing factors.

  • Add missing alerts, dashboards, tests and runbooks.

  • Fix systemic issues (missing timeouts, non-idempotent consumers) across services.

Interview Tip

Lead with observability (traces, logs, metrics tied together by IDs), then describe a systematic process: check recent changes, locate the origin, compare good vs bad, mitigate first. A short real example, such as finding a retry storm through tracing, makes the answer convincing.

61

What are key considerations in mobile application architecture?

Mobile application architecture must handle unreliable networks, limited battery and resources, many device types and OS versions, app store release cycles, security on devices you do not control, and strict user expectations for speed. Key decisions include the app’s internal architecture pattern (MVVM, MVI, clean architecture), offline and sync strategy, API design for mobile clients, state and data management, security, performance, and release and update strategy.

Read full answer

Applies tonative (Kotlin/Jetpack Compose, Swift/SwiftUI) and cross-platform apps (Flutter, React Native, Kotlin Multiplatform)

Internal App Architecture

  • Layered structure: UI layer, domain layer (use cases, business rules), data layer (repositories, network, local database).

  • Presentation patterns: MVVM is the common choice on Android and iOS; MVI or unidirectional data flow (Redux-like) for predictable state.

  • Dependency injection (Hilt, Koin, Swift dependency containers) for testability.

  • Modularization by feature for large apps, speeding builds and team ownership.

Native vs Cross-Platform

Option Strengths Trade-offs
Native (Swift, Kotlin) Best performance, full platform APIs, platform look and feel Two codebases
Flutter / React Native One codebase, faster delivery Bridges for some native features, larger app size, framework dependency
Kotlin Multiplatform Shared business logic, native UI Less mature tooling for some areas

Offline-First and Data

  • Local database (Room, SQLite, Core Data / SwiftData, Realm) as the source for the UI.

  • Sync strategy: background sync, queued writes, conflict resolution.

  • Caching with clear invalidation rules.

  • Design UI to show cached data and pending states instead of spinners.

Network and API Design

  • Backend for Frontend (BFF) or GraphQL to fetch exactly what screens need in few round trips.

  • Pagination, compression and efficient formats.

  • Retries with backoff, timeouts and handling of offline states.

  • Push notifications (APNs, FCM) instead of polling.

  • API versioning: old app versions stay installed for months; the backend must support them.

Performance and Resources

  • Fast startup: lazy initialization, minimal work on the main thread.

  • Battery: batch network calls, use OS schedulers (WorkManager, BGTaskScheduler), avoid constant GPS or wake locks.

  • Memory: efficient image loading and caching, avoid leaks.

  • App size: modular delivery, asset optimization.

Security

  • Store secrets and tokens in the Keychain (iOS) or Keystore (Android), never in plain preferences.

  • TLS everywhere; consider certificate pinning for high-risk apps (with a rotation plan).

  • Never trust the client: enforce authorization on the server; apps can be reverse-engineered.

  • OAuth 2.0 with PKCE for login; biometric authentication for sensitive actions.

  • Follow OWASP Mobile Application Security guidance (MASVS).

Release and Operations

  • App store review delays mean fixes are not instant: use feature flags and remote configuration.

  • Forced or soft updates for critical fixes and minimum supported versions.

  • Crash reporting and analytics (Firebase Crashlytics, Sentry).

  • Staged rollouts on Google Play and phased releases on the App Store.

  • Automated UI tests across device sizes and OS versions.

Accessibility and UX

Support dynamic text sizes, screen readers (TalkBack, VoiceOver), dark mode, different screen sizes and orientations, and localization.

Interview Tip

Organize the answer around constraints (network, battery, devices, store releases, security) and how architecture addresses each. Mentioning that the backend must support old app versions and that feature flags compensate for slow store releases shows practical experience.

62

How does IoT architecture differ from traditional architecture?

IoT architecture differs because it must connect huge numbers of constrained, physically distributed devices over unreliable, low-bandwidth networks, process continuous streams of sensor data, often act in real time at the edge, and manage device provisioning, firmware updates and security for years in the field. Traditional architectures mainly serve human users through browsers or apps on reliable networks, with servers fully under the operator’s control.

Read full answer

Applies toIoT system design (protocols such as MQTT, CoAP, LwM2M; platforms such as AWS IoT Core, Azure IoT Hub, ThingsBoard, EMQX)

Key Differences

Aspect Traditional architecture IoT architecture
Clients Browsers, mobile apps, other services Sensors, actuators, gateways, embedded devices
Scale of clients Thousands to millions of users Often millions of devices, each always connected or reporting
Device resources Capable machines Constrained CPU, memory, power (battery-operated)
Network Reliable broadband Intermittent, low bandwidth (cellular, LoRaWAN, NB-IoT, BLE, Zigbee)
Traffic pattern Request-response, user-driven Continuous telemetry, events, commands to devices
Protocols HTTP, gRPC, WebSockets MQTT, CoAP, LwM2M, plus HTTP for some devices
Processing location Data centre or cloud Device, edge gateway and cloud
Lifecycle Servers updated frequently Devices deployed for 5–15 years; updates over the air
Security Controlled servers, user authentication Physical access to devices, device identity, secure boot
Data Business transactions High-volume time-series sensor data
Physical impact Mainly digital Actuators affect the physical world (safety concerns)

Typical IoT Layers

  1. Device layer: sensors and actuators with firmware.

  2. Connectivity / gateway layer: protocol translation, local buffering, edge processing.

  3. Ingestion layer: MQTT brokers or IoT hubs handling device connections and messaging.

  4. Processing layer: stream processing, rules engines, alerting.

  5. Storage layer: time-series databases (InfluxDB, TimescaleDB), data lakes.

  6. Application layer: dashboards, APIs, mobile apps, ML analytics.

  7. Device management: provisioning, configuration, OTA firmware updates, monitoring.

IoT-Specific Concerns

  • Device identity and provisioning: unique certificates per device, secure onboarding at scale.

  • Device twins / shadows: cloud copy of the desired and reported state, so commands can be applied when devices reconnect.

  • Store-and-forward: devices and gateways buffer data while offline.

  • OTA updates: signed firmware, staged rollouts, rollback if update fails.

  • Edge computing: filter, aggregate or act locally to cut latency and bandwidth.

  • Time-series data management: retention policies, downsampling.

  • Safety: actuator commands validated and rate-limited; devices default to safe states on failure.

Example

A smart building system:

  • Temperature sensors send readings every minute over Zigbee to a gateway.

  • The gateway aggregates readings and controls HVAC locally if the internet is down.

  • It publishes summaries via MQTT to the cloud.

  • The cloud stores time series, detects anomalies and pushes new schedules back to the gateway through a device twin.

  • Firmware updates roll out to 5% of devices first.

Interview Tip

Highlight constrained devices, unreliable networks, edge processing, telemetry streams, device lifecycle management and physical security. Mentioning MQTT, device twins and OTA update strategy shows practical IoT knowledge.

63

What is the role of edge computing in IoT architecture?

Edge computing processes data close to where it is generated (on devices or local gateways) instead of sending everything to the cloud. In IoT it reduces latency for real-time control, saves bandwidth and cost by filtering and aggregating data, keeps systems working offline, and improves privacy by keeping sensitive data local. The cloud still handles global analytics, long-term storage, fleet management and model training.

Read full answer

Applies toIoT architecture (edge platforms such as AWS IoT Greengrass, Azure IoT Edge, KubeEdge, K3s; industrial gateways)

Where Processing Happens

Tier Typical work
Device Sampling, simple thresholds, compression
Edge gateway / on-site server Protocol translation, aggregation, local rules, ML inference, buffering
Cloud Fleet-wide analytics, storage, dashboards, model training, device management

Roles of Edge Computing

  • Low latency and real-time control: a factory machine must stop within milliseconds when a sensor detects a fault; a round trip to the cloud is too slow and unreliable.

  • Bandwidth reduction: a camera streams video locally; the edge runs object detection and sends only events (“person detected at gate 3”) to the cloud.

  • Offline operation: a farm irrigation system keeps running schedules and safety rules during connectivity loss, syncing later.

  • Privacy and compliance: process personal or sensitive data locally (for example, video anonymized before upload) to meet data protection or residency rules.

  • Cost: less data transferred and stored in the cloud.

  • Protocol bridging: translate industrial protocols (Modbus, OPC UA, BACnet) to MQTT or HTTP.

Edge Architecture Patterns

  • Filter and aggregate: send averages, minimums and maximums each minute instead of every reading.

  • Event detection: only forward anomalies or threshold crossings.

  • Edge ML inference: models trained in the cloud, deployed to the edge, retrained with collected data.

  • Store-and-forward: buffer data locally during outages.

  • Local digital twin: keep the state of local devices for fast decisions.

Challenges

Challenge Mitigation
Managing many distributed edge nodes Central orchestration, containerized workloads, GitOps
Software and model updates Signed packages, staged rollouts, automatic rollback
Physical security Secure boot, disk encryption, tamper detection, hardware security modules or TPMs
Limited hardware Lightweight runtimes, optimized models (quantization)
Data consistency with cloud Clear source of truth, conflict rules, idempotent sync
Monitoring Health and metrics forwarded to central observability

Edge vs Cloud Trade-offs

  • Edge gives speed, resilience and privacy but adds operational complexity and hardware cost.

  • Cloud gives scale, simpler operations and global insight but depends on connectivity and adds latency.

  • Most systems use a hybrid: time-critical and bandwidth-heavy work at the edge, everything else in the cloud.

Example

A wind farm:

  • Each turbine’s controller adjusts blade pitch locally in real time.

  • An on-site edge server collects vibration data at high frequency, runs anomaly detection and stores raw data for a week.

  • It sends summaries and anomaly alerts to the cloud, where models are retrained across all farms and pushed back to the edge.

Interview Tip

Explain the device, edge and cloud tiers and the reasons for edge processing (latency, bandwidth, offline operation, privacy). Interviewers value acknowledging the operational burden of managing many edge nodes and how you would handle updates and security.

64

How do you design data synchronization for mobile apps?

Mobile data synchronization is designed around an offline-first model: the app reads and writes to a local database, records changes in an outbox, and a background sync engine exchanges changes with the server using incremental (delta) sync, idempotent operations, and a defined conflict-resolution strategy. The server remains the source of truth, and the UI shows sync state clearly.

Read full answer

Applies tomobile and offline-capable apps (SQLite/Room, Core Data/SwiftData, Realm; sync services such as Firebase Firestore, AWS AppSync, Couchbase Lite, PowerSync, or custom APIs)

Architecture

UI ↔ Local database ↔ Sync engine (outbox, pull, conflict handling) ↔ Sync API ↔ Server database

  • The UI only talks to the local database, so it works offline and stays fast.

  • The sync engine runs in the background (Android WorkManager, iOS background tasks) when connectivity is available.

Pushing Local Changes

  1. Each local change is written to the local table and an outbox (pending operations) in one transaction.

  2. Each operation has a client-generated ID (UUID) and an idempotency key, so retries do not create duplicates.

  3. The engine sends batches to the server, in order where order matters.

  4. On success, the outbox entry is removed and the record marked synced; on failure, it retries with backoff.

Pulling Server Changes

  • Delta sync: the client sends a cursor (last sync token or server change sequence number) and receives only changes since then.

  • Server tracks updated_at or a monotonically increasing version per record, plus tombstones for deletes so clients can remove records.

  • Push notifications or WebSockets can trigger a pull when relevant data changes.

  • Use pagination for large initial syncs.

Conflict Resolution

Conflicts occur when the same record changes on two devices (or device and server) before syncing.

Strategy How it works Good for
Last write wins (by server order) Latest accepted change replaces others Simple settings, low-value data
Field-level merge Merge non-overlapping field changes Profiles, forms
Version check (optimistic concurrency) Server rejects stale updates; client resolves Business records
Domain rules Custom logic (e.g. stock cannot go negative) Inventory, bookings
User resolution Show both versions Documents, notes
CRDTs Data types that merge automatically Collaborative editing, counters, lists

Avoid relying on device clocks for ordering; they can be wrong. Use server-assigned versions or logical clocks.

Other Design Points

  • Selective sync: sync only data the user needs (their projects, last 90 days), keeping local storage small.

  • Schema versioning: old app versions may still sync; the API must handle them.

  • Security: encrypt sensitive local data, scope sync to the user’s authorization, revoke local data on logout.

  • Bandwidth and battery: batch requests, compress payloads, sync on Wi-Fi for large files.

  • Large files: upload and download separately with resumable transfers, linked by IDs.

  • Sync state in the UI: pending, synced, failed indicators.

Example

A field inspection app:

  • Inspectors fill forms offline; each form and photo is saved locally with a UUID.

  • When the connection returns, the outbox uploads forms, then photos with resumable uploads.

  • The app pulls new assignments since the last cursor.

  • If an office user edited the same inspection, field-level merge applies; conflicting fields are shown to the inspector.

Interview Tip

Describe local-first storage, an outbox with idempotent operations, delta sync with cursors and tombstones, and an explicit conflict strategy. Saying not to trust device clocks and mentioning CRDTs for collaborative data are strong signals.

65

How do you design mobile and IoT apps for battery and resource limits?

Designing for battery and resource constraints means doing less work, less often, and in batches: minimize radio usage (the network is often the largest power cost), let the operating system schedule background work, use sensors and location sparingly, keep memory and CPU usage low, move heavy computation to servers or edge gateways where sensible, and measure energy use on real devices.

Read full answer

Applies tomobile apps (Android, iOS) and battery-powered IoT devices

Network Efficiency (Usually the Biggest Gain)

  • Batch requests: waking the cellular radio has a fixed energy cost, and the radio stays in a high-power state for a while afterwards. Ten small requests spread over a minute cost far more than one combined request.

  • Use push instead of polling: APNs or FCM wakes the app only when needed.

  • Delta sync and compression: send only changes, in compact formats (protobuf, CBOR for IoT).

  • Cache aggressively with proper validation (ETags).

  • Defer large transfers to Wi-Fi and charging when possible.

Background Work

  • Use OS schedulers: WorkManager on Android, BGTaskScheduler on iOS. They group work across apps and respect Doze mode and Low Power Mode.

  • Avoid long-running services, frequent wake-ups and persistent wake locks.

  • Set constraints on tasks (requires network, charging, idle).

Sensors and Location

  • Request the lowest accuracy and frequency that meets the need (city-level or significant location changes instead of continuous GPS).

  • Use geofencing and activity recognition instead of constant tracking.

  • Stop sensors immediately when not needed (camera, Bluetooth scanning).

CPU, Memory and UI

  • Keep work off the main thread; avoid unnecessary recomputation.

  • Load and decode images at the displayed size; use efficient caching libraries.

  • Limit animations and screen refreshes; use dark themes on OLED screens where appropriate.

  • Fix memory leaks; large memory usage leads to app termination and slow restarts.

  • Use efficient on-device ML (quantized models, hardware accelerators) or offload inference to servers.

IoT Device Techniques

  • Duty cycling: sleep most of the time, wake to sample and transmit, then sleep again. A sensor that sleeps 99% of the time can run for years on a battery.

  • Low-power protocols: BLE, Zigbee, LoRaWAN, NB-IoT, LTE-M; MQTT or CoAP with small payloads.

  • Edge filtering: send only changes or threshold events instead of every reading.

  • Power-saving modes of cellular modules (PSM, eDRX).

  • Efficient firmware updates: delta updates to reduce transfer time.

  • Design hardware and firmware together: low-power microcontrollers, sensor selection.

Measuring

  • Android: Battery Historian, Android Studio Energy Profiler, Android vitals in the Play Console.

  • iOS: Xcode Energy Organizer and Instruments, MetricKit.

  • IoT: measure current draw over a full duty cycle and estimate battery life; test in real network conditions (weak signal increases transmit power).

Trade-offs

Choice Benefit Cost
Less frequent sync Longer battery life Staler data
Lower location accuracy Less power Less precise features
Offloading computation to cloud Less device CPU More network use and latency
On-device processing Less network use, works offline More CPU and memory

The right balance depends on the feature: a navigation app needs precise GPS while active, a weather app does not.

Interview Tip

Emphasize network batching, OS-managed background work, sensible sensor use, and measuring on real devices. For IoT, mention duty cycling and low-power protocols; giving the trade-off between freshness and battery life shows good judgement.

66

What are the principles of RESTful architecture?

REST (Representational State Transfer) is an architectural style defined by Roy Fielding for distributed hypermedia systems. Its principles are a client-server separation, statelessness, cacheability, a uniform interface (resources identified by URIs, manipulated through representations, self-descriptive messages, and hypermedia links), a layered system, and optional code on demand. In practice, RESTful APIs model resources and use standard HTTP methods, status codes and caching.

Read full answer

Applies toHTTP API design (REST as defined by Fielding, plus common practice for JSON APIs)

Fielding’s Constraints

Constraint Meaning Benefit
Client-server UI concerns separated from data storage and logic Independent evolution
Stateless Each request contains everything needed; no client session state on the server Easy horizontal scaling and recovery
Cacheable Responses state whether they can be cached Lower latency and server load
Uniform interface Consistent way of identifying and manipulating resources Simplicity, decoupling
Layered system Clients cannot tell if they talk to the server or an intermediary (proxy, CDN, gateway) Load balancing, security layers
Code on demand (optional) Server can send executable code (such as JavaScript) Extensible clients

The Uniform Interface in Detail

  1. Resource identification: everything important is a resource with a URI, such as /orders/123.

  2. Manipulation through representations: clients send and receive representations (JSON, XML) of resource state.

  3. Self-descriptive messages: methods, headers and media types explain how to process a message.

  4. Hypermedia as the engine of application state (HATEOAS): responses include links to related resources and available actions.

Practical REST API Conventions

Resources as nouns

  • GET /customers/42/orders rather than GET /getOrdersForCustomer?id=42.

HTTP methods with correct semantics

Method Use Safe Idempotent
GET Read Yes Yes
POST Create or trigger processing No No
PUT Replace a resource No Yes
PATCH Partial update No Not guaranteed
DELETE Remove No Yes

Meaningful status codes

  • 200 OK, 201 Created (with a Location header), 204 No Content

  • 400 Bad Request, 401 Unauthorized, 403 Forbidden, 404 Not Found, 409 Conflict, 422 Unprocessable Content, 429 Too Many Requests

  • 500 Internal Server Error, 503 Service Unavailable

Caching and concurrency

  • Cache-Control, ETag and If-None-Match for conditional requests.

  • If-Match with ETags for optimistic concurrency on updates.

Other practices

  • Filtering, sorting and pagination with query parameters (?status=shipped&limit=50&cursor=...).

  • Consistent error format (for example RFC 9457 Problem Details).

  • Versioning strategy and backward-compatible evolution.

  • Documentation with OpenAPI.

Example

GET /orders/123 HTTP/1.1
Accept: application/json

HTTP/1.1 200 OK
ETag: "v7"
Cache-Control: private, max-age=60

{"id": 123, "status": "shipped",
 "links": {"customer": "/customers/42", "invoice": "/orders/123/invoice"}}

Trade-offs

  • Simple, widely understood, and works with HTTP caching and tooling.

  • Over-fetching and under-fetching: fixed resource shapes may need several calls for one screen (GraphQL or BFFs address this).

  • Fully hypermedia-driven APIs are rare; most “REST” APIs use resources and HTTP correctly but skip HATEOAS.

  • Less suited to streaming or high-performance internal calls, where gRPC or WebSockets may fit better.

Interview Tip

List Fielding’s constraints, then show practical conventions: resources, correct method semantics, idempotency, status codes and caching. Noting that most real-world APIs are not fully RESTful because they skip HATEOAS shows depth.

67

What should you consider when designing a GraphQL API?

Designing a GraphQL API means designing a strongly typed schema around client needs and then protecting the server from the flexibility clients get. Key considerations are schema design (types, nullability, naming, pagination), performance (the N+1 problem, batching with DataLoader, caching), security (authorization per field, query depth and cost limits), error handling, schema evolution without versions, and operational concerns such as monitoring per operation.

Read full answer

Applies toGraphQL servers (Apollo Server, GraphQL Java, Hot Chocolate, graphql-ruby, Strawberry) and federation (Apollo Federation, GraphQL Mesh)

Schema Design

  • Model the domain and client use cases, not the database tables.

  • Use clear, consistent names (Order, customer, createOrder).

  • Nullability: mark fields non-null (!) only when they will always be present; a non-null field that fails nulls out its parent.

  • Pagination: use cursor-based connections (edges, node, pageInfo) for lists that can grow.

  • Mutations: one input object per mutation (createOrder(input: CreateOrderInput!)), returning a payload type with the result and user-facing errors.

  • Use enums, custom scalars (DateTime, Money) and interfaces/unions where they fit.

Performance

  • N+1 problem: resolving orders { customer { name } } naively runs one customer query per order. Use DataLoader (batching and per-request caching) to combine them into one query.

  • Caching: HTTP caching is harder because most requests are POSTs to one URL. Options: persisted queries over GET, response caching per field or type, client-side normalized caches (Apollo Client, Relay).

  • Limit list sizes with required pagination arguments.

  • Monitor resolver timings to find slow fields.

Security

  • Authorization in resolvers or the business layer, per field and object, not only at the endpoint.

  • Query depth limits and query cost analysis to stop expensive or malicious nested queries.

  • Rate limiting based on query cost, not just request count.

  • Persisted queries / allowlists for public clients, so only known operations run.

  • Consider disabling introspection in production for private APIs (it does not replace real security).

  • Validate inputs as with any API.

Error Handling

  • GraphQL returns 200 OK with an errors array for many failures, so monitoring must inspect response bodies.

  • Distinguish system errors (in errors) from business errors (modelled in the payload, such as OrderError with a code), so clients can handle them in a typed way.

  • Partial results are possible: one field fails while others succeed.

Schema Evolution

  • GraphQL encourages evolving one schema instead of versioning.

  • Add fields and types freely; deprecate fields with @deprecated(reason: "...").

  • Track field usage per client to know when deprecated fields can be removed.

  • Run schema checks in CI (breaking change detection against real client operations).

Architecture Options

  • Single GraphQL server in front of REST services or databases.

  • BFF style: GraphQL as the API layer for web and mobile.

  • Federation: each team owns a subgraph; a router composes them into one supergraph.

When GraphQL Fits (and When It Does Not)

Fits well Less suitable
Many clients with different data needs Simple CRUD with one client
Mobile apps needing fewer round trips Large file uploads and downloads
Aggregating many back-end services Heavy reliance on HTTP/CDN caching
Rapidly evolving UIs Public APIs where consumers expect REST

Example

type Query {
  order(id: ID!): Order
  orders(first: Int!, after: String): OrderConnection!
}

type Order {
  id: ID!
  status: OrderStatus!
  total: Money!
  customer: Customer!
}

Interview Tip

Cover schema design, N+1 with DataLoader, authorization per field, depth and cost limits, and evolution through deprecation. Mentioning that errors come back with 200 OK and need special monitoring is a detail interviewers appreciate.

68

When should you use WebSockets in a system?

Use WebSockets when you need persistent, low-latency, two-way communication between client and server, where either side can send messages at any time: chat, multiplayer games, collaborative editing, live trading screens, real-time dashboards and live notifications. Avoid them for ordinary request-response operations, infrequent updates, or one-way streams, where HTTP, Server-Sent Events (SSE) or long polling are simpler.

Read full answer

Applies toweb and mobile real-time communication (WebSocket protocol, RFC 6455; libraries such as Socket.IO, ws, SignalR, Phoenix Channels, Action Cable; managed services such as AWS API Gateway WebSockets, Ably, Pusher)

How WebSockets Work

  1. The client sends an HTTP request with Upgrade: websocket.

  2. The server responds 101 Switching Protocols.

  3. The same TCP connection then carries framed messages in both directions until either side closes it.

There is no new HTTP request per message, so overhead and latency are low.

Good Use Cases

  • Chat and messaging: users send and receive instantly.

  • Collaborative tools: shared documents, whiteboards, cursors.

  • Multiplayer games: frequent small state updates.

  • Financial data: prices updating many times per second, with client subscriptions.

  • Live operations dashboards with interactive filters.

  • IoT control panels sending commands and receiving device status.

Alternatives Compared

Option Direction Best for Notes
Regular HTTP Request-response CRUD, most APIs Simplest, cacheable
Short polling Client asks repeatedly Rare updates, simple systems Wasteful at scale
Long polling Server holds request until data Fallback, moderate real-time Works everywhere, higher overhead
Server-Sent Events Server to client only Notifications, live feeds, progress updates Uses HTTP, automatic reconnection
WebSockets Both directions Interactive real-time apps Most flexible, more complex to operate
WebTransport Both directions over HTTP/3 Emerging low-latency use cases Newer, less widely supported

Architecture Considerations

  • Stateful connections: each server holds open connections, so scaling needs care:

  • Load balancers must support WebSockets and long-lived connections.

  • Use a pub/sub backbone (Redis Pub/Sub, NATS, Kafka) so a message reaching one server can be delivered to users connected to others.

  • Connection limits: plan memory and file descriptors per server; a single server can typically hold tens of thousands or more connections, depending on implementation.

  • Reconnection: clients must reconnect with backoff and resume (send the last message ID received to fetch missed messages).

  • Heartbeats: ping/pong frames detect dead connections and keep idle connections alive through proxies.

  • Authentication: authenticate during the handshake (token or cookie) and check authorization for each subscription; re-validate on token expiry.

  • Message protocol: define message types, versioning and acknowledgements on top of raw WebSockets.

  • Backpressure: handle slow clients so outgoing buffers do not grow without limit.

  • Deployments: draining connections gracefully when servers restart.

Security

  • Use wss:// (TLS).

  • Check the Origin header to prevent cross-site WebSocket hijacking.

  • Rate-limit messages per connection and validate every message.

When Not to Use Them

  • Updates every few minutes: polling or SSE is simpler.

  • One-way server-to-client streams: SSE is easier and works with HTTP infrastructure.

  • Standard CRUD operations: keep them on HTTP APIs even in apps that also use WebSockets.

Interview Tip

Justify WebSockets by bidirectional, low-latency needs, compare with SSE and long polling, and discuss scaling stateful connections with a pub/sub layer. Mentioning reconnection with resume and Origin checks shows production experience.

69

What is long polling and when is it useful?

Long polling is a technique where the client sends an HTTP request and the server holds it open until new data is available or a timeout expires, then responds. The client immediately sends another request. It gives near real-time updates using plain HTTP, which makes it useful when WebSockets or Server-Sent Events are unavailable or blocked, for moderate update rates, and as a fallback in real-time libraries.

Read full answer

Applies toweb and API communication patterns

How It Works

  1. Client sends GET /messages?since=1043.

  2. If messages newer than 1043 exist, the server responds immediately.

  3. If not, the server waits (for example up to 30 seconds).

  4. When a message arrives, the server responds with it; if the timeout expires, it responds with an empty result (204 No Content or an empty list).

  5. The client processes the response and immediately sends a new request with the latest cursor.

Comparison

Technique Latency Overhead Complexity
Short polling (every N seconds) Up to N seconds High: many empty responses Very low
Long polling Near real time Moderate: one request per update or timeout Low
Server-Sent Events Real time, server to client Low: one long-lived HTTP response Low
WebSockets Real time, both directions Lowest per message Higher

When It Is Useful

  • Restrictive networks or proxies that break WebSockets or long-lived streams.

  • Low to moderate update rates: notifications, job status, new emails.

  • Simple infrastructure: works with existing HTTP servers, authentication and load balancers.

  • Fallback transport: libraries such as Socket.IO or SignalR fall back to long polling when better options fail.

  • APIs for external clients where requiring WebSockets would be a barrier. Telegram’s Bot API (getUpdates) is a well-known example of long polling.

  • Message queue consumption: Amazon SQS long polling (WaitTimeSeconds up to 20 seconds) reduces empty receives and cost.

Design Considerations

  • Cursors or sequence numbers so no messages are lost between requests and duplicates can be detected.

  • Timeouts below proxy and load balancer limits (for example 25–30 seconds if the proxy cuts at 60).

  • Asynchronous servers (Node.js, Netty, async frameworks) so holding thousands of open requests does not consume a thread each.

  • Pub/sub backbone (such as Redis) so the server holding a client’s request is notified when data arrives, even if another instance received it.

  • Client backoff on errors to avoid hammering the server.

  • Batch messages: return everything accumulated since the cursor in one response.

Limitations

  • Each update still costs a full HTTP request and response, including headers.

  • With very frequent updates, it effectively becomes rapid polling; SSE or WebSockets are better.

  • Messages from client to server still need separate requests.

  • Many held connections consume server resources and can complicate scaling.

Example

A build server UI shows job status. The browser calls GET /jobs/88/status?version=5; the server waits until the status changes to version 6 (or 30 seconds pass), responds, and the browser immediately asks for version 7. Users see updates within milliseconds of a change without WebSocket infrastructure.

Interview Tip

Explain the request-hold-respond-repeat cycle, compare it to short polling, SSE and WebSockets, and give concrete scenarios: fallbacks, restrictive networks, SQS long polling. Mentioning cursors to avoid losing messages is a good detail.

70

How do you handle network latency in system design?

Network latency is handled by reducing the number of network round trips, moving data and computation closer to users, avoiding unnecessary synchronous calls, caching, overlapping work through parallel and asynchronous processing, and designing timeouts and user experiences that tolerate delay. Because latency is limited by physics (distance) and cannot be eliminated, good designs measure it and keep it off the critical path wherever possible.

Read full answer

Applies togeneral distributed system and API design

Useful Latency Numbers (Approximate)

Path Round trip
Same data centre Under 1 ms
Between availability zones in a region About 1–2 ms
Across a continent 30–80 ms
Across oceans (e.g. India to US) 150–250 ms
Mobile networks 30–100+ ms, highly variable

A page that makes 10 sequential calls across an ocean can spend 2 seconds on network waiting alone.

Strategies

1. Fewer round trips

  • Combine requests: batch APIs, GraphQL, or a BFF that aggregates data for a screen.

  • Avoid chatty service-to-service designs (one call per item in a loop).

  • Use HTTP/2 or HTTP/3 multiplexing and keep-alive connections to avoid repeated TCP and TLS handshakes.

2. Move data closer to users

  • CDNs for static assets and cacheable responses.

  • Edge computing for personalization or validation near users.

  • Multi-region deployments with read replicas close to users.

3. Cache

  • Client-side, CDN, application (Redis) and database caches.

  • Precompute expensive results.

4. Parallelize and go asynchronous

  • Call independent services in parallel rather than sequentially.

  • Move non-critical work (emails, analytics, image processing) to queues.

  • Return quickly (202 Accepted) for long tasks and notify on completion.

5. Reduce payload size

  • Compression (gzip, Brotli), efficient formats (protobuf), pagination, fetching only needed fields.

6. Tolerate latency

  • Timeouts on every call, tuned to measured percentiles.

  • Hedged requests: send a second request if the first is slow, use whichever returns first (for idempotent reads).

  • Optimistic UI: update the screen immediately and reconcile with the server later.

  • Prefetching likely next data.

  • Skeleton screens and progressive loading.

Measure the Right Things

  • Track p50, p95 and p99 latency, not only averages; tail latency matters because a page that calls many services is affected by the slowest one.

  • Use distributed tracing to see where time goes.

  • Monitor real user metrics (RUM) by region and network type.

Example

A product page in a global shop:

  • Static assets and images served from a CDN.

  • One BFF call returns product, price and stock, fetched in parallel from three services in the same region.

  • Reviews load asynchronously after the main content.

  • Users in Asia are served from an Asian region with a read replica; writes such as orders go to their home region.

Result: page render time drops from 1.8 s to 400 ms for distant users.

Trade-offs

  • Caching and replicas introduce staleness and consistency questions.

  • Multi-region adds cost and complexity, especially for writes.

  • Async processing means eventual consistency and more complex user flows.

Interview Tip

Quote rough latency numbers, then explain fewer round trips, proximity (CDN, regions), caching, parallelism and async work. Mentioning tail latency (p99) and fan-out effects shows strong system design understanding.

71

How do you assess the quality of a software architecture?

Architecture quality is assessed by checking how well the architecture meets its business goals and quality attribute requirements (performance, availability, security, modifiability, cost), not by how elegant it looks. The main tools are explicit, measurable quality attribute scenarios, structured reviews (such as ATAM or lightweight architecture reviews), analysis of the code and runtime (dependency structure, metrics, incidents), architecture fitness functions that check properties automatically, and delivery metrics that show whether the architecture helps teams change software safely.

Read full answer

Applies toarchitecture evaluation practice

1. Start From Requirements

  • Identify business drivers: why the system exists and what success looks like.

  • Define quality attribute scenarios that are measurable, for example:

  • “Under 2,000 orders per minute, 99% of checkout requests complete in under 800 ms.”

  • “A new payment provider can be added by one team in under two weeks.”

  • “Loss of one availability zone causes no more than 5 minutes of degraded service.”

2. Review the Design

  • Scenario-based evaluation (ATAM, or lighter versions): walk through scenarios and see how the architecture handles each; identify risks, sensitivity points and trade-offs.

  • Check against principles: clear module boundaries, data ownership, no single points of failure, security controls at trust boundaries.

  • Review decisions: are ADRs present, are trade-offs understood?

  • Threat modelling for security (for example STRIDE).

3. Analyse the Implementation

Architecture on paper often differs from the code.

  • Dependency analysis: cycles, layering violations, modules depending on internals of others.

  • Coupling and cohesion metrics; change coupling (files that always change together across modules).

  • Hotspots: complex code that changes frequently.

  • Technical debt and outdated dependencies.

4. Observe Runtime Behaviour

  • SLO compliance: latency, availability and error rates against targets.

  • Load and stress test results.

  • Incident history: recurring causes often point to architectural weaknesses (shared database, missing timeouts).

  • Cost per transaction or per user.

5. Measure Delivery

The DORA metrics indicate whether the architecture supports change:

Metric What it suggests
Deployment frequency Can teams release independently?
Lead time for changes How easy is change?
Change failure rate How risky are changes?
Time to restore service How recoverable is the system?

Also look at how many teams must coordinate for a typical feature; heavy coordination often reveals poor boundaries.

6. Automate With Fitness Functions

  • Architecture tests (ArchUnit, dependency-cruiser) enforcing layering and module rules.

  • Performance budgets in CI.

  • Security scans and policy checks.

  • Chaos experiments verifying resilience scenarios.

Signs of a Good vs Weak Architecture

Good signs Warning signs
Features usually touch one module or team Every change touches many services
Clear data ownership Shared databases across teams
SLOs met with headroom Frequent performance incidents
Independent deployments Coordinated “release trains” required for everything
Decisions documented with trade-offs Nobody knows why things are the way they are

Interview Tip

Anchor the assessment in measurable quality attribute scenarios, then combine design reviews, code analysis, runtime data and delivery metrics. Mentioning ATAM and fitness functions, and that quality is judged against goals rather than against a fashionable style, shows maturity.

72

What is ATAM (Architecture Tradeoff Analysis Method)?

ATAM (Architecture Tradeoff Analysis Method) is a structured, scenario-based method developed by the Software Engineering Institute (SEI) at Carnegie Mellon University for evaluating a software architecture against its quality attribute goals. It brings together architects and stakeholders to identify risks, non-risks, sensitivity points and trade-off points, showing how architectural decisions affect qualities such as performance, availability, security and modifiability.

Read full answer

Applies toarchitecture evaluation practice (SEI ATAM; lighter variants are often used in industry)

Goals of ATAM

  • Make quality attribute requirements explicit and prioritized.

  • Understand how architectural approaches support or harm those requirements.

  • Discover risks early, before they become expensive to fix.

  • Build shared understanding between business and technical stakeholders.

Key Concepts

Term Meaning Example
Quality attribute scenario A concrete, measurable situation “At peak load, 99% of searches return in under 1 s”
Utility tree Hierarchy of quality goals refined into prioritized scenarios Performance → latency → search scenario (High importance, Medium difficulty)
Risk A decision that may cause a quality goal to fail Single database for search and orders under peak load
Non-risk A decision judged safe Stateless web tier behind a load balancer
Sensitivity point A property strongly affected by one decision Cache TTL directly affects freshness and load
Trade-off point A decision affecting several qualities in opposite directions Encryption of all internal traffic: better security, some latency cost
Risk theme Group of related risks pointing to systemic issues “Insufficient isolation of shared resources”

The Steps (Two Main Phases with Stakeholders)

Phase 1: Evaluation team with architects and project leaders

  1. Present ATAM to participants.

  2. Present business drivers.

  3. Present the architecture.

  4. Identify architectural approaches (patterns and tactics used).

  5. Generate the quality attribute utility tree and prioritize scenarios.

  6. Analyse architectural approaches against the high-priority scenarios.

Phase 2: Wider stakeholder group

  1. Brainstorm and prioritize scenarios with all stakeholders.

  2. Analyse approaches again for the new high-priority scenarios.

  3. Present results: risks, non-risks, sensitivity points, trade-offs and risk themes.

Phase 0 (preparation) and a follow-up phase are also commonly described.

Outputs

  • Documented architectural approaches.

  • Prioritized scenarios and utility tree.

  • Lists of risks, non-risks, sensitivity points and trade-offs.

  • Risk themes linked to business goals, which guide what to fix.

Strengths and Limitations

Strengths Limitations
Systematic and repeatable Heavyweight: several days and many participants
Brings stakeholders together Depends on skilled facilitators
Focuses on business-relevant qualities Evaluates a design at a point in time
Finds risks before implementation Does not produce a design; it evaluates one

Lightweight Use in Practice

Many teams use a “mini-ATAM”: a half-day workshop that defines the top 5–10 quality scenarios, walks through how the architecture handles them, and records risks and trade-offs as ADRs or backlog items. Continuous checks with fitness functions complement these reviews.

Interview Tip

Define ATAM, explain scenarios and the utility tree, and clearly distinguish risks, sensitivity points and trade-off points with examples. Saying you would run a lightweight version for most projects shows pragmatism.

73

What are architecture fitness functions?

Architecture fitness functions are objective, ideally automated checks that measure how well a system meets a specific architectural characteristic, such as layering rules, performance budgets, security policies or resilience. The idea comes from Building Evolutionary Architectures (Ford, Parsons, Kua): just as a fitness function in evolutionary computing scores candidate solutions, architecture fitness functions continuously verify that the system stays aligned with its intended architecture as it evolves.

Read full answer

Applies toevolutionary architecture practice (tools such as ArchUnit, NetArchTest, dependency-cruiser, import-linter, k6, Lighthouse CI, OPA/Conftest, Chaos Mesh)

Why They Matter

  • Architecture erodes over time: shortcuts add forbidden dependencies, performance slowly degrades, security settings drift.

  • Documents and reviews do not catch these quickly.

  • Fitness functions turn architectural intent into executable guardrails that run in CI/CD or production, giving fast feedback.

Types of Fitness Functions

Dimension Options
Scope Atomic (one characteristic) or holistic (several together, e.g. performance under failure)
Trigger Triggered (on commit, in pipeline) or continuous (monitoring in production)
Timing Static (code analysis) or dynamic (running system)
Automation Automated or manual (e.g. a periodic review checklist)

Examples

Structure and dependencies

  • The domain layer must not depend on web or database frameworks.

  • No cyclic dependencies between modules.

  • Only the billing module may access billing tables.

@ArchTest
static final ArchRule domainIsIndependent =
    noClasses().that().resideInAPackage("..domain..")
        .should().dependOnClassesThat()
        .resideInAnyPackage("..web..", "..persistence..");

Performance

  • p95 latency of the search API under 300 ms in a load test run in the pipeline.

  • Front-end bundle size under 250 KB; Lighthouse performance score above a threshold.

Security and compliance

  • No critical vulnerabilities in dependencies.

  • All storage buckets encrypted and not public (policy as code in infrastructure checks).

  • No secrets in the repository.

Resilience and operations

  • Chaos experiment: killing one instance keeps error rate below 0.1%.

  • Every service exposes health checks and metrics.

  • Backup restore completes within the RTO in a scheduled test.

Production monitoring as fitness functions

  • SLO error budgets: alert when availability falls below target.

  • Cost per transaction stays within budget.

How to Introduce Them

  1. Identify the most important architectural characteristics (from quality attribute scenarios or ADRs).

  2. Define measurable thresholds for each.

  3. Automate the cheapest checks first (dependency rules, static analysis).

  4. Add them to CI/CD so violations fail the build or raise warnings.

  5. Review thresholds regularly as requirements change.

  6. Link each fitness function to the decision it protects (for example from an ADR).

Pitfalls

  • Too many or too strict rules that block teams without clear value.

  • Vague goals that cannot be measured (“the system should be scalable”).

  • Flaky performance tests that teams learn to ignore.

  • Not updating fitness functions when the architecture intentionally changes.

Interview Tip

Define them as automated, objective checks of architectural characteristics, give concrete examples across structure, performance, security and resilience, and explain that they make architecture governance continuous instead of a one-off review.

74

What methodologies are used to analyze system performance?

Performance analysis combines methodologies that tell you what to look at with testing and measurement that tell you what is happening. Common methodologies include the USE method (Utilization, Saturation, Errors for resources), the RED method (Rate, Errors, Duration for services), the Four Golden Signals, workload characterization, latency analysis and profiling, queueing theory and capacity modelling, and structured load, stress, soak and spike testing, all supported by distributed tracing and real user monitoring.

Read full answer

Applies toperformance engineering for services, databases and front ends

Resource and Service Methodologies

Method Focus Questions
USE (Brendan Gregg) Every resource (CPU, memory, disk, network, connection pools) How busy is it? Is work queuing? Are there errors?
RED (Tom Wilkie) Every service or endpoint Requests per second, failed requests, how long they take
Four Golden Signals (Google SRE) User-facing systems Latency, traffic, errors, saturation

USE finds bottlenecked resources; RED and golden signals show user impact.

Analysis Approaches

  • Workload characterization: who calls the system, which operations, how often, with what data sizes and patterns (peaks, batch jobs).

  • Latency breakdown: use distributed tracing to see time spent per service, database and external call.

  • Profiling: CPU profilers, flame graphs, memory and allocation profilers, lock contention analysis; continuous profiling in production.

  • Database analysis: slow query logs, query plans (EXPLAIN ANALYZE), index usage, lock waits.

  • Drill-down analysis: start at the high level (service slow), narrow down (endpoint, query, function).

  • Scientific method: form a hypothesis, change one variable, measure, compare.

Performance Testing Types

Test Purpose
Load test Behaviour at expected and peak load
Stress test Find the breaking point and failure behaviour
Spike test Sudden traffic surges
Soak (endurance) test Leaks and degradation over hours
Scalability test How throughput changes as resources are added
Benchmark / micro-benchmark Compare implementations of a component

Tools: k6, Gatling, JMeter, Locust, wrk; JMH for Java micro-benchmarks.

Modelling and Capacity Planning

  • Little’s Law: average items in the system = arrival rate × average time in system. For example, 200 requests per second with 0.5 s average latency means about 100 requests in flight, which sizes thread or connection pools.

  • Queueing theory: as utilization approaches 100%, waiting time rises sharply; plan for headroom (often keeping key resources below about 70–80% at peak).

  • Amdahl’s Law and the Universal Scalability Law: explain why adding resources gives diminishing returns due to serial parts and coordination costs.

Measuring Correctly

  • Use percentiles (p50, p95, p99, p99.9), not averages.

  • Watch for coordinated omission in load tests, which hides real latency when the load generator waits for slow responses.

  • Test in production-like environments with realistic data volumes.

  • Compare against baselines to detect regressions.

  • Real user monitoring (RUM) and Core Web Vitals for front-end performance.

Example Workflow

  1. Users report slow checkout; RED dashboards show p99 rising from 600 ms to 3 s.

  2. Tracing shows most time in the inventory service.

  3. USE analysis of inventory’s database shows connection pool saturation.

  4. Profiling and query plans reveal a missing index after a recent schema change.

  5. Add the index; load test confirms p99 back under 700 ms; add a regression test to the pipeline.

Interview Tip

Name USE and RED and explain when to use each, mention tracing and profiling for drill-down, and cover test types plus Little’s Law for capacity. Emphasizing percentiles over averages is a detail interviewers often look for.

75

What is risk-driven architecture?

Risk-driven architecture is an approach in which the amount and focus of architecture work is guided by the risks a system faces. Instead of designing everything up front or doing no design at all, architects identify the biggest technical and business risks, apply design techniques (prototypes, analysis, patterns, models) only until those risks are reduced to an acceptable level, and then move on. The idea is described by George Fairbanks in Just Enough Software Architecture.

Read full answer

Applies toarchitecture practice and planning (agile and traditional projects)

Core Idea

  • Architecture effort is expensive; spend it where failure would hurt most.

  • Low-risk areas (standard CRUD, known technology) need little design.

  • High-risk areas (unknown scale, new technology, strict latency, regulatory requirements) deserve deliberate design and validation.

The Process

  1. Identify and prioritize risks

  2. Technical: “Can the system process 50,000 events per second?”, “Will the new database handle our query patterns?”

  3. Quality attributes: security, availability, latency.

  4. Integration: unknown third-party APIs, legacy systems.

  5. Organizational: team skills, dependencies between teams.

  6. Select techniques to reduce each risk:

  7. Prototypes and spikes.

  8. Load tests and benchmarks.

  9. Threat modelling.

  10. Architecture models and calculations (capacity estimates, failure analysis).

  11. Proven patterns and tactics.

  12. Apply them and evaluate results.

  13. Stop when the risk is acceptable, then continue with delivery; revisit as new risks appear.

Example

A team builds a real-time bidding platform for ads:

Risk Technique Outcome
Must respond within 100 ms at 20,000 requests per second Prototype bidding service with in-memory data; load test Feasible with caching and a compiled language
Budget data must be consistent across regions Design analysis of consistency options Accept per-region budgets with periodic reconciliation
New cloud stream processing service unknown to team Spike for one week Chosen, with fallback plan
Admin portal Little design needed Standard web app

The team spent most architecture effort on the first two risks, not on the admin portal.

Benefits

  • Avoids big design up front for areas that do not need it.

  • Avoids no design where mistakes would be expensive.

  • Provides a clear rationale for architecture work in agile projects: each design activity addresses a named risk.

  • Early discovery of infeasible requirements.

Relation to Other Practices

  • ATAM and architecture reviews also identify risks; risk-driven architecture uses risks to plan ongoing design effort.

  • Spikes and proof-of-concepts in agile are risk-reduction techniques.

  • The Spiral Model (Boehm) is an earlier risk-driven process model at project level.

  • Fitness functions monitor that risks stay controlled over time.

Pitfalls

  • Identifying risks vaguely (“performance might be an issue”) instead of concretely and measurably.

  • Ignoring business and organizational risks.

  • Treating risk analysis as a one-time activity.

  • Stopping too early because a prototype ran on a laptop without realistic load or data.

Interview Tip

Define the approach (“design is proportional to risk”), describe the identify, prioritize, mitigate, re-evaluate loop, and give an example table of risks and techniques. Mentioning Fairbanks’ Just Enough Software Architecture adds credibility.

76

What role does AI play in software architecture?

AI plays two roles in software architecture: AI as a component of systems (LLMs, ML models and recommendation engines that architects must integrate, operate and govern), and AI as a tool for architects and developers (assisting with code generation, design exploration, documentation, analysis and operations). Both require architects to manage new concerns such as non-deterministic behaviour, data pipelines, model lifecycle, cost, latency, security and evaluation.

Read full answer

Applies tocurrent architecture practice (LLM APIs, ML platforms, retrieval-augmented generation, MLOps tooling, AI coding assistants)

AI as Part of the System

New architectural building blocks:

  • Model serving: hosted LLM APIs or self-hosted models behind an inference service.

  • Retrieval-Augmented Generation (RAG): documents chunked and embedded into a vector store (pgvector, Pinecone, Weaviate, OpenSearch); relevant passages retrieved and passed to the model for grounded answers.

  • Agents and tool calling: models call internal APIs to perform tasks, requiring strict permissions.

  • Feature stores and training pipelines for traditional ML.

  • Evaluation and monitoring: quality metrics, drift detection, human review loops.

Architectural Concerns

Concern Considerations
Non-determinism Outputs vary; validate structured outputs with schemas; design for human review where errors matter
Latency Model calls can take seconds; use streaming responses, caching, smaller models, async processing
Cost Usage-based pricing; route simple tasks to cheaper models, cache results, cap tokens
Reliability Fallbacks when a provider is down; timeouts; multiple providers via an abstraction layer
Security Prompt injection, data leakage, excessive tool permissions; follow OWASP Top 10 for LLM Applications
Privacy and compliance What data is sent to providers, retention, regional hosting, regulations (e.g. the EU AI Act)
Quality evaluation Test sets, automated evaluation, A/B tests, feedback capture
Model lifecycle Versioning prompts and models, regression tests when changing either
Observability Log prompts, responses, token usage, latency (with sensitive data protected)

AI as a Tool for Architects and Teams

  • Code generation and review assistance (AI coding assistants), with human review.

  • Exploring design options: generating alternatives and trade-off comparisons as a starting point.

  • Documentation: drafting ADRs, diagrams-as-code and API docs from code.

  • Analysis of large codebases: summarizing modules, finding dependencies, supporting migrations.

  • Operations (AIOps): anomaly detection, log clustering, incident summarization.

  • Test generation and test data creation.

Architects remain responsible for decisions: AI suggestions can be plausible but wrong, outdated or insecure, and need verification.

Example Architecture

A customer support assistant:

  1. A user question goes to an API gateway and support service.

  2. The service retrieves relevant help articles from a vector index (RAG).

  3. An LLM generates an answer constrained to retrieved content.

  4. A guardrail layer checks for policy violations and personal data.

  5. If confidence is low or the request involves refunds, the case is routed to a human agent.

  6. Responses, ratings and costs are logged for evaluation and improvement.

Interview Tip

Distinguish AI inside the system from AI assisting the team. Focus on architectural concerns (non-determinism, evaluation, cost, latency, security such as prompt injection) and patterns like RAG and human-in-the-loop. Interviewers value a balanced view: useful capabilities with explicit guardrails.

77

How do you integrate blockchain into a software architecture?

Blockchain is integrated as a specialized component for shared, tamper-evident records among parties who do not fully trust each other, not as a general-purpose database. A typical architecture keeps most data and logic off-chain in conventional services, puts only the minimal state, proofs or settlement on-chain via smart contracts, and connects the two through gateway services, event indexers, oracles and secure key management. The first step is confirming that a blockchain is actually needed.

Read full answer

Applies toenterprise and Web3 architectures (public chains such as Ethereum and its layer-2 networks; permissioned platforms such as Hyperledger Fabric; libraries such as ethers.js, web3.py, web3j)

Do You Need a Blockchain?

A blockchain makes sense when all of these apply:

  • Multiple organizations must share and write to the same data.

  • They do not want to trust a single operator.

  • Tamper-evident history or verifiable execution is essential.

  • A traditional shared database with audit logs, signatures or a trusted third party is not acceptable.

Otherwise, a conventional database (possibly with append-only audit logs or a ledger database) is simpler, faster and cheaper.

Typical Integration Architecture

Users / systems → Application services → Blockchain gateway (signing, nonce management, retries) → Smart contracts on chain

Chain events → Indexer → Off-chain database → APIs and UIs

Components:

  • Smart contracts: minimal on-chain logic (token transfers, asset ownership, settlement rules).

  • Off-chain services: business logic, user management, large data, search and reporting.

  • Gateway service: builds and signs transactions, manages nonces and gas or fees, retries, tracks confirmations.

  • Event indexer: listens to contract events and writes them to a queryable database (custom listeners or tools such as The Graph); querying the chain directly for every UI request is slow.

  • Oracles: bring external data on-chain (prices, delivery confirmations) through trusted providers such as Chainlink.

  • Off-chain storage for documents (object storage or IPFS), with only hashes stored on-chain for integrity.

  • Key management: HSMs, cloud KMS or custody services; user wallets for self-custody.

Key Design Considerations

Concern Approach
Throughput and latency Use layer-2 networks or permissioned chains; keep on-chain operations few
Finality Wait for enough confirmations (or chain finality) before acting off-chain; handle reorganizations
Cost Fees on public chains; batch operations, store hashes rather than data
Privacy Public chains are transparent; keep personal data off-chain; consider permissioned networks or zero-knowledge proofs
Immutability vs regulations Never store personal data on-chain (right to erasure); store references or hashes
Upgradability Contracts are hard to change; use upgrade patterns carefully, with governance
Security Audit smart contracts, test thoroughly, protect keys; contract bugs can be irreversible
Eventual consistency Off-chain views lag the chain; design UIs for pending states

Example

A supply-chain consortium tracks certified shipments:

  1. Each company runs its own systems and a node on a permissioned network.

  2. When goods change custody, the company’s service submits a signed transaction recording the shipment ID, the new owner and a hash of the certificate.

  3. Certificates are stored off-chain; anyone can verify them against the on-chain hash.

  4. An indexer populates a database for dashboards and searches.

Interview Tip

Start by questioning whether blockchain is needed, then describe the on-chain/off-chain split, gateway, indexer, oracles and key management. Mentioning finality, privacy (no personal data on-chain) and smart contract audits shows a realistic, architecture-focused view.

78

How might quantum computing impact software architecture?

Quantum computing will affect software architecture mainly in two ways. First, security: large, fault-tolerant quantum computers could break today’s widely used public-key cryptography (RSA, elliptic-curve), so architectures must become crypto-agile and migrate to post-quantum cryptography (PQC), a change that is needed now. Second, computation: quantum processors will be used as specialized accelerators for certain problems, accessed through cloud services in hybrid classical-quantum workflows, not as replacements for ordinary servers.

Read full answer

Applies tolong-term architecture planning (NIST post-quantum standards; quantum cloud services such as IBM Quantum, Amazon Braket, Azure Quantum; SDKs such as Qiskit and Cirq)

1. Security Impact: Post-Quantum Cryptography

  • Shor’s algorithm on a sufficiently large fault-tolerant quantum computer could break RSA, Diffie-Hellman and elliptic-curve cryptography, which protect TLS, VPNs, code signing and certificates.

  • Grover’s algorithm offers only a quadratic speed-up against symmetric encryption and hashes, so AES-256 and SHA-256 or SHA-384 remain strong with adequate key sizes.

  • “Harvest now, decrypt later”: attackers can record encrypted traffic today and decrypt it once capable machines exist. Data that must stay confidential for many years is already at risk.

  • NIST standardized PQC algorithms in 2024: ML-KEM (from CRYSTALS-Kyber) for key exchange, and ML-DSA (from CRYSTALS-Dilithium) and SLH-DSA (from SPHINCS+) for signatures, with further algorithms in progress.

Architectural actions

  • Inventory cryptography: where keys, certificates and algorithms are used, including in third-party products.

  • Crypto-agility: avoid hard-coding algorithms; centralize cryptography in libraries, services or gateways so algorithms can be swapped.

  • Hybrid key exchange (classical plus post-quantum) is already being deployed in TLS by major browsers and CDNs.

  • Plan for larger keys and signatures: PQC keys and signatures are bigger, affecting certificate sizes, handshake latency and constrained devices.

  • Prioritize long-lived secrets and devices (IoT devices deployed for 10+ years, archives, firmware signing).

2. Computation Impact: Quantum as an Accelerator

Promising areas (still mostly research or early experiments):

  • Simulation of molecules and materials (chemistry, drug discovery, batteries).

  • Certain optimization problems (logistics, portfolio optimization), though advantages over classical methods are not yet proven for practical problems.

  • Some sampling and machine learning tasks under research.

Architecture pattern: hybrid workflows

  1. A classical application prepares a problem.

  2. A job is submitted to a quantum cloud service (similar to calling a GPU cluster or batch service).

  3. Results return probabilistically and are post-processed classically.

  4. Results feed back into normal business systems.

Architectural concerns

  • Treat quantum services as asynchronous, queued, expensive external dependencies.

  • Results are probabilistic; run multiple shots and validate.

  • Isolate quantum-specific code behind interfaces so providers and algorithms can change.

  • Keep classical fallbacks.

3. What Will Not Change Soon

  • Web apps, databases, APIs and most business logic will remain classical.

  • Current quantum hardware is noisy and small; broad practical advantage requires error-corrected machines, and timelines are uncertain.

Interview Tip

Lead with the most actionable point: post-quantum cryptography and crypto-agility, including “harvest now, decrypt later”. Then describe quantum computing as a specialized cloud accelerator in hybrid workflows. Avoid exaggerated claims about quantum replacing classical computing.

79

What architectural considerations apply to AR and VR applications?

AR (augmented reality) and VR (virtual reality) applications must render complex 3D scenes at high, stable frame rates with very low motion-to-photon latency, because delays cause discomfort and motion sickness. Architecture must therefore address real-time rendering performance, on-device vs cloud or edge processing, spatial tracking and world understanding, asset streaming, multi-user synchronization, device diversity, and privacy for camera and sensor data.

Read full answer

Applies toXR applications (engines such as Unity and Unreal; standards and SDKs such as OpenXR, WebXR, ARKit, ARCore; headsets and mobile devices)

Performance Requirements

  • Typical headset targets are 72–120 frames per second, giving a frame budget of about 8–14 ms for game logic, physics and rendering.

  • Motion-to-photon latency should stay around 20 ms or less for comfort.

  • Rendering runs twice (one view per eye) in VR.

  • Techniques: level of detail, occlusion culling, foveated rendering (with eye tracking), baked lighting, efficient shaders, asynchronous reprojection.

Client Architecture

  • Engine-based structure (Unity or Unreal) with an entity-component or scene-graph model.

  • Separate rendering, input/tracking, physics, networking and audio systems.

  • Keep the render loop free of blocking work: load assets and make network calls asynchronously.

  • Use OpenXR to support multiple headsets through one API.

  • Design input abstraction for controllers, hand tracking, eye tracking and voice.

On-Device vs Edge vs Cloud

Location Use for Trade-off
On device Tracking, rendering, interaction Limited by battery, heat, compute
Edge Low-latency offloading (split rendering, heavy AI) Needs nearby infrastructure and good networks
Cloud Asset storage, user data, multiplayer state, analytics Too slow for per-frame work

Cloud or edge rendering streams frames to lightweight devices, but requires very low network latency and reprojection on the device to hide delays.

Spatial and World Understanding (Especially AR)

  • SLAM (simultaneous localization and mapping), plane detection, meshing and light estimation through ARKit or ARCore.

  • Anchors to place virtual content in the real world; cloud anchors to share positions between users and sessions.

  • Handle tracking loss gracefully (low light, fast movement).

Content and Assets

  • 3D models, textures and audio can be large: use compressed formats (glTF/GLB, Basis Universal or KTX2 textures), progressive loading and CDNs.

  • Download content in packs on demand rather than bundling everything in the app.

  • Content pipelines to optimize assets for different device capabilities.

Multi-User Experiences

  • Real-time networking (UDP-based protocols, dedicated servers or relay services).

  • State synchronization of avatars and objects with interpolation and prediction to hide latency.

  • Authoritative server to prevent cheating and resolve conflicts.

  • Voice chat and spatial audio.

Privacy and Safety

  • Cameras, room scans, eye tracking and body movement are highly sensitive data: minimize collection, process on device, obtain clear consent.

  • Physical safety: boundary systems (guardians), avoiding sudden movements, comfort settings.

  • Accessibility: seated modes, subtitles, alternative inputs.

Testing and Operations

  • Performance profiling on real target devices, not only on development PCs.

  • Telemetry for frame times, crashes and comfort issues.

  • Automated tests for logic; manual testing for comfort and interaction.

Interview Tip

Focus on the frame-time budget and latency requirements, then explain how they shape decisions: what runs on device versus edge or cloud, asynchronous asset streaming, and networking for multi-user sessions. Mentioning OpenXR and the privacy of sensor data rounds out the answer.

80

How does 5G affect software architecture?

5G affects software architecture by offering higher bandwidth, lower latency and support for far more connected devices than 4G, together with network slicing and multi-access edge computing (MEC). This makes it practical to move latency-sensitive work to edge locations near users, connect massive IoT fleets, stream rich media, and build real-time applications on mobile networks. Architects must still design for variable real-world performance, because actual 5G latency and speed depend on spectrum, coverage and network load.

Read full answer

Applies tomobile, IoT and edge architectures (telecom edge platforms such as AWS Wavelength and Azure operator edge offerings; private 5G networks)

5G Capabilities (3GPP Categories)

Capability Meaning Typical use
eMBB (enhanced mobile broadband) Much higher throughput Video streaming, AR/VR, large downloads
URLLC (ultra-reliable low-latency communication) Very low latency and high reliability targets Industrial automation, remote control, vehicle communication
mMTC (massive machine-type communication) Very high device density Smart meters, sensors, smart cities

Note: 5G targets very low radio latency (around 1 ms for URLLC), but end-to-end latency to a distant cloud region still includes internet and data centre hops, often tens of milliseconds. Low latency is achieved only when processing is close to the network edge.

Architectural Impacts

1. Edge computing becomes central

  • MEC places compute inside or near the operator’s network.

  • Latency-sensitive components (video analytics, game servers, AR rendering, industrial control) run at the edge, while the core cloud handles storage, analytics and management.

  • Architectures become multi-tier: device, edge, regional cloud.

2. Massive IoT at scale

  • Back ends must handle many more devices and connections: scalable MQTT brokers, partitioned ingestion, time-series storage.

  • Device management and security for large fleets.

3. Network slicing

  • Operators can provide virtual networks with guaranteed characteristics (bandwidth, latency) for specific applications or customers.

  • Applications can be designed around quality-of-service tiers, though availability depends on operators and commercial agreements.

4. Richer real-time mobile experiences

  • High-quality video, cloud gaming, AR collaboration and real-time telemetry become viable on mobile networks.

  • Less need to compromise designs for slow connections, in covered areas.

5. Private 5G networks

  • Factories, ports and campuses deploy private 5G for reliable wireless connectivity of machines and robots, integrating with on-premises edge servers.

Design Considerations

  • Do not assume 5G everywhere: coverage varies, and devices fall back to 4G or Wi-Fi. Design adaptive bitrate, offline support and graceful degradation.

  • Distributed deployment and orchestration: many edge sites require automated deployment (Kubernetes at the edge, GitOps) and remote monitoring.

  • State management: keep edge services stateless where possible, or replicate state carefully when users move between edge zones.

  • Security: more devices and edge sites increase the attack surface; use zero-trust principles, device identity and encryption.

  • Cost and vendor dependence: edge platforms are often tied to specific operators and cloud providers.

  • Battery and data costs on devices still matter.

Example

A port uses private 5G:

  • Cameras on cranes stream video to on-site edge servers running container recognition.

  • Autonomous vehicles receive routing updates with low latency.

  • Summarized operational data flows to the cloud for planning and analytics.

  • If the 5G network degrades, vehicles switch to safe local behaviour.

Interview Tip

Explain the three 5G categories, then focus on architectural consequences: edge computing, massive IoT ingestion, network slicing and private networks. Pointing out that end-to-end latency depends on where processing runs, and that coverage varies, shows practical understanding.

81

How do you explain architecture decisions to non-technical stakeholders?

Explain architecture decisions to non-technical stakeholders by starting from the business problem and outcome, describing options and trade-offs in terms they care about (cost, time to market, risk, customer experience, compliance), using simple visuals and analogies, giving a clear recommendation with its consequences, and leaving out jargon unless it is needed. The goal is a shared, informed decision, not a technical lecture.

Read full answer

Applies toarchitect communication and stakeholder management

A Simple Structure

  1. Context: what business goal or problem this decision serves.

  2. The decision needed: one sentence.

  3. Options: two or three realistic choices.

  4. Trade-offs in business terms.

  5. Recommendation and why.

  6. What it means for them: cost, timeline, risks, what they need to approve.

Translate Technical Qualities Into Business Terms

Technical concern Business translation
Scalability “Handles the expected 5x Diwali sale traffic without slowing down”
Availability “Checkout down for at most about 45 minutes per month at 99.9%”
Technical debt “Each new pricing feature currently takes 6 weeks instead of 2”
Security “Reduces the risk of a data breach and the resulting fines and reputational damage”
Vendor lock-in “Switching providers later would take about 6 months of work”
Latency “Pages load in under 2 seconds, which keeps more customers buying”

Example

Decision: Build our own payment integration layer or use a payment orchestration provider.

  • Option A, build: about 4 months of work for two developers, full control, lower per-transaction fees after year two.

  • Option B, buy: live in 4 weeks, monthly fee plus a small per-transaction cost, easy to add new payment methods.

  • Recommendation: Option B now, because the marketing launch is in two months and expected volume does not yet justify building. Revisit when monthly volume passes a defined threshold.

This framing lets a product owner or CFO make an informed choice without understanding APIs.

Communication Techniques

  • Visuals: simple boxes-and-arrows context diagrams, timelines, cost comparison charts. Avoid detailed technical diagrams.

  • Analogies with care: “A cache is like keeping frequently used files on your desk instead of in the archive room.”

  • Numbers and ranges: costs, timelines, probabilities of risk, rather than vague words like “complex”.

  • Stories and scenarios: “If the payment provider is down on sale day, this is what customers see.”

  • Be honest about uncertainty and how you will reduce it (prototypes, phased rollouts).

Tailor to the Audience

Stakeholder Focus on
Executives Strategy, cost, risk, competitive advantage
Product managers Features, timelines, flexibility for future requirements
Finance Total cost of ownership, licences, cloud costs
Legal and compliance Data protection, regulatory risk, auditability
Operations and support Reliability, incident impact, staffing

Pitfalls

  • Jargon (“we’ll use event sourcing with CQRS over Kafka”) without explaining the benefit.

  • Presenting only one option, which looks like a decision already made.

  • Hiding downsides, which damages trust when they appear later.

  • Too much detail: keep the technical appendix available for those who ask.

Interview Tip

Show a clear structure (context, options, trade-offs, recommendation, impact) and give an example where you translated a technical concern into cost, risk or time. Interviewers look for empathy for the audience and honesty about trade-offs.

82

What is the role of an architect in agile teams?

In agile teams the architect is a collaborative guide rather than a gatekeeper who designs everything up front. The role is to set a clear technical vision and guardrails, make or facilitate important decisions at the right time, reduce major risks early (through spikes and prototypes), keep the architecture evolvable as requirements change, and coach teams so they can make good local decisions themselves. Architects stay close to the code and to delivery.

Read full answer

Applies toagile and DevOps organizations (Scrum, Kanban, scaled frameworks such as SAFe or LeSS)

Responsibilities

  • Technical vision: target architecture and principles aligned with business strategy.

  • Guardrails, not blueprints: standards for security, APIs, observability and data ownership; teams decide within them.

  • Decision-making at the last responsible moment: decide early when changes are expensive (data models, platforms), defer others until more is known.

  • Architectural runway: ensure the platform, infrastructure and key components are ready just ahead of the features that need them.

  • Risk reduction: run spikes, proofs of concept and load tests for uncertain areas.

  • Quality attributes: make non-functional requirements visible (as acceptance criteria, definitions of done, or fitness functions).

  • Cross-team alignment: integration, shared contracts, avoiding duplicated solutions.

  • Coaching and mentoring: pairing, design reviews, knowledge sharing.

  • Managing technical debt: making it visible and helping prioritize it with product owners.

How Architects Work in Agile Rhythms

Activity Architect contribution
Backlog refinement Identify technical dependencies, risks, enabler stories
Sprint or iteration planning Help size architectural work, flag cross-team impacts
Development Pair on complex parts, review designs and key pull requests
Reviews and demos Check that quality attributes are met
Retrospectives Raise architectural pain points and improvements
Program or quarterly planning Plan architecture runway and cross-team dependencies

Styles of Agile Architecture Roles

  • Architect embedded in a team: a senior developer with architecture responsibility.

  • Architect serving several teams: coordinates shared concerns, facilitates decisions.

  • Enterprise or solution architects in scaled frameworks: set broader standards and roadmaps.

  • Architecture as a shared responsibility: architecture guilds or communities of practice where developers across teams decide together.

Tools and Practices

  • Architecture Decision Records (ADRs) for transparent decisions.

  • Lightweight diagrams (C4) kept current in the repository.

  • Fitness functions to enforce guardrails automatically.

  • Evolutionary architecture techniques: modular design, strangler fig, feature flags.

  • Inner source and paved roads: templates and platforms that make the right way the easy way.

Anti-Patterns

  • Ivory-tower architect: produces designs that teams ignore because they do not reflect reality.

  • No architecture at all: each team optimizes locally, creating inconsistent, fragile systems.

  • Architect as bottleneck: every decision needs approval, slowing delivery.

  • Big design up front that cannot adapt to feedback.

Interview Tip

Describe the architect as a facilitator who provides vision, guardrails and runway while teams make most decisions. Mention concrete practices such as ADRs, spikes, fitness functions and participation in refinement, and contrast them with the ivory-tower anti-pattern.

83

How do you handle conflicting architectural decisions?

Conflicting architectural decisions are handled by making the conflict explicit, returning to shared goals and quality attribute priorities, evaluating options against agreed criteria with evidence (data, prototypes, cost estimates), deciding through a clear decision process with defined ownership, and recording the outcome and trade-offs in an Architecture Decision Record, so the decision can be revisited if circumstances change.

Read full answer

Applies toarchitecture governance and team collaboration

Common Sources of Conflict

  • Competing quality attributes: performance vs security, consistency vs availability, speed of delivery vs maintainability.

  • Different team or stakeholder priorities: product wants features fast, operations wants stability, security wants controls.

  • Local vs global optimization: a team’s preferred technology vs organizational standards.

  • Past decisions that no longer fit new requirements.

  • Personal preferences presented as technical arguments.

A Structured Approach

  1. Clarify the problem: what decision is needed, by when, and what happens if it is not made.

  2. Identify the shared goals: business objectives and prioritized quality attributes (for example from a utility tree).

  3. List options fairly, including each party’s proposal and perhaps a compromise.

  4. Define evaluation criteria and weights together before scoring, to reduce bias.

  5. Gather evidence: benchmarks, spikes, cost models, risk analysis, input from experts.

  6. Compare options in a decision matrix.

  7. Decide using the agreed decision process.

  8. Document in an ADR with consequences and a review trigger.

  9. Commit and support the decision, even if you disagreed (“disagree and commit”).

Example Decision Matrix

Two teams disagree: one wants a shared PostgreSQL database for speed, the other wants separate databases per service.

Criterion (weight) Shared database Database per service
Time to first release (3) 5 3
Team independence (4) 2 5
Operational cost (2) 4 3
Data consistency ease (3) 5 3
Long-term scalability (3) 2 4
Weighted total 52 56

The result favours database per service, with a mitigation: start with separate schemas on the same database cluster, giving most of the independence benefits while reducing operational cost early.

Decision-Making Models

  • Clear ownership: the team owning the component decides local matters; an architecture group decides cross-cutting ones.

  • Consent-based decisions: proceed unless someone has a reasoned objection.

  • Architecture advice process: anyone can decide, after consulting affected people and experts.

  • Escalation path with time limits, so conflicts do not stall delivery.

Interpersonal Aspects

  • Focus on interests, not positions: ask why each side prefers its option.

  • Separate people from problems; keep discussions evidence-based.

  • Make sure quieter stakeholders are heard.

  • Acknowledge valid concerns of the option not chosen and address them with mitigations.

Revisiting Decisions

  • Record assumptions and conditions that would trigger review (for example “if traffic exceeds 10x”).

  • Supersede ADRs explicitly instead of quietly changing direction.

  • Use fitness functions and metrics to see whether the decision works.

Interview Tip

Show a structured, evidence-based process: shared goals, agreed criteria, options, data, a clear decision owner and an ADR. A brief example with a compromise solution and “disagree and commit” demonstrates both technical and leadership maturity.

84

What are Architecture Decision Records (ADRs)?

Architecture Decision Records (ADRs) are short documents that capture one significant architectural decision: its context, the decision made, the alternatives considered, and its consequences. Stored with the code and kept as an immutable, numbered log, they explain why the system is built the way it is, help onboard new team members, prevent repeated debates and make it easy to revisit decisions when circumstances change. The format was popularized by Michael Nygard in 2011.

Read full answer

Applies toarchitecture documentation practice (formats such as Nygard's template and MADR; tools such as adr-tools and Log4brains, or plain Markdown in the repository)

What Counts as a Significant Decision

Decisions that are costly to change or affect quality attributes or many teams, for example:

  • Choosing a database, message broker or cloud platform.

  • Adopting microservices or a modular monolith.

  • Selecting an authentication approach.

  • Defining API versioning or event schema rules.

  • Deciding on data retention or multi-tenancy model.

Small implementation details do not need ADRs.

Typical Structure (Nygard Format)

  1. Title: numbered and descriptive, for example “ADR-007: Use Kafka for order events”.

  2. Status: Proposed, Accepted, Deprecated or Superseded by ADR-0xx.

  3. Context: the forces at play: requirements, constraints, problems.

  4. Decision: what was decided, stated actively (“We will…”).

  5. Consequences: positive, negative and neutral effects.

Templates such as MADR add considered options with pros and cons, and decision drivers.

Example

# ADR-007: Use Kafka for order events

Status: Accepted (2026-03-14)

## Context
Order, billing, warehouse and analytics systems need order updates.
Point-to-point HTTP calls cause tight coupling and failures when one
system is down. Analytics needs to replay historical events.

## Options considered
1. Direct HTTP callbacks
2. RabbitMQ topic exchange
3. Kafka topics

## Decision
We will publish order events to Kafka, keyed by order ID,
using the transactional outbox pattern.

## Consequences
+ Consumers are decoupled and can replay events.
+ Per-order ordering is preserved.
- The platform team must operate Kafka (or we pay for a managed service).
- Consumers must be idempotent; events are delivered at least once.

Practices

  • Store ADRs in the repository (for example docs/adr/) and review them in pull requests.

  • Keep them short: one or two pages.

  • Never rewrite accepted ADRs to change the decision; write a new ADR that supersedes the old one, preserving history.

  • Write them when the decision is made, not months later.

  • Link ADRs to related ones, issues and fitness functions.

  • Include review triggers or assumptions, for example “revisit if message volume exceeds a defined threshold”.

Benefits

  • Preserves rationale that is otherwise lost when people leave.

  • Speeds onboarding.

  • Reduces repeated debates about settled questions.

  • Supports architecture reviews and audits.

  • Encourages deliberate thinking about alternatives and trade-offs.

Pitfalls

  • Writing ADRs for trivial decisions, creating noise.

  • Recording only the decision without context or alternatives.

  • Storing them in a place nobody reads.

  • Letting the status field become outdated.

Interview Tip

Describe the structure (context, decision, consequences, status), stress immutability and supersession, and give an example. Explaining that ADRs capture the why, not just the what, is the key point interviewers look for.

85

How do you ensure architectural guidelines are followed across teams?

Architectural guidelines are followed best when they are few, clear and justified, created with the teams, made easy to follow through templates, shared libraries and platforms (“paved roads”), and checked automatically with fitness functions and policy-as-code. Human practices, such as lightweight reviews, ADRs, communities of practice and visible metrics, cover what automation cannot. Enforcement should focus on what really matters (security, interoperability, data ownership) while giving teams freedom elsewhere.

Read full answer

Applies toarchitecture governance in multi-team organizations

1. Write Good Guidelines

  • Few and essential: focus on cross-cutting concerns (security, APIs, observability, data, resilience).

  • Explain the why (link to ADRs or principles), so teams understand the reasoning.

  • Make them concrete: “Every service exposes /health and Prometheus metrics” rather than “services should be observable”.

  • Distinguish levels: mandatory standards, recommended defaults, and areas of team choice.

  • Co-create with engineers through an architecture guild or review process, increasing buy-in.

2. Make the Right Way the Easy Way

  • Service templates and scaffolding with logging, metrics, tracing, CI pipelines and security settings preconfigured.

  • Shared libraries for authentication, API clients and error handling.

  • Internal developer platforms (for example built on Backstage) offering approved databases, queues and deployment paths.

  • Reference implementations and examples teams can copy.

When following guidelines saves time, adoption happens naturally.

3. Automate Checks

Area Automated check
Code structure Architecture tests (ArchUnit, dependency-cruiser)
APIs OpenAPI linting (Spectral), breaking-change detection
Infrastructure Policy as code (OPA/Conftest, Checkov), cloud guardrails
Security Dependency and container scanning, secret detection
Operations Checks that services define health endpoints, alerts and SLOs
Kubernetes Admission policies (Kyverno, OPA Gatekeeper)

Automated checks give fast, consistent feedback and reduce review bottlenecks.

4. Lightweight Human Governance

  • Architecture reviews for significant changes, focused on risks rather than approvals of every detail.

  • ADRs recorded by teams and visible to others.

  • Architecture advice process: teams decide after consulting affected parties and architects.

  • Communities of practice / guilds that share knowledge and evolve guidelines.

  • Office hours with architects for quick guidance.

5. Visibility and Feedback

  • Scorecards per service (for example in a developer portal): ownership, documentation, test coverage, security posture, SLO definitions.

  • Make compliance trends visible to leadership without using them to blame teams.

  • Collect feedback: frequent exceptions indicate a guideline that may need changing.

6. Handle Exceptions

  • Allow documented exceptions with an ADR explaining why, risks and a review date.

  • Revisit guidelines when exceptions become common.

Example

An organization wants every service to be observable:

  1. The guideline explains why (faster incident resolution) and what is required.

  2. The service template includes OpenTelemetry, structured logging and default dashboards.

  3. A CI check verifies that the metrics endpoint and trace configuration exist.

  4. The developer portal shows a scorecard per service.

  5. The observability guild reviews feedback quarterly and updates the guideline.

Adoption rises without a central team reviewing every service.

Interview Tip

Combine “make it easy” (templates, platforms), “make it automatic” (fitness functions, policy as code) and “make it collaborative” (guilds, ADRs, advice process). Interviewers value seeing that governance enables teams rather than blocking them.

Sign in to keep reading

You've opened 2 full answers. Sign in to read all 85 Software Architecture answers, mark what you know and pick up where you left off.

Report a mistake

What's wrong?

All System Design subjects