Architectural styles: layered, client–server, microservices and MVC
Clear study notes on four architectural styles — layered, client–server, microservices and MVC — with definitions, diagrams to draw, examples, common exam mistakes and short practice questions.
Drafted with Aria, reviewed by the AiCanCode.org team · Updated . How we write and check our notes. Spotted an error? Use Give Feedback at the bottom of the page.
Why it matters
Software architects and engineers use architectural styles to choose how a system is organised so it is maintainable, scalable and testable. Choosing between layered, client–server, microservices and MVC affects development teams, deployment, performance and how requirements from the business are satisfied.
Key ideas
Start from first principles: a software architecture style is a set of structural constraints and interaction rules that give a system predictable properties.
Architecture style (defined): a set of constraints on component types and permitted interactions, applied to achieve desired quality attributes (scalability, modifiability, performance). Define before using: architecture style limits how components are arranged and communicate.
Layered architecture (defined): a style where the system is organised into horizontal layers; each layer offers services to the layer above and uses services from the layer below. Typical layers: Presentation, Application (or Service), Domain (Business Logic), Data Access, and Database. Assumption: interactions are primarily vertical between adjacent layers. This style enforces separation of concerns and supports incremental replacement of layers.
- Exact definition students should write: "A layered architecture partitions the system into distinct layers where each layer has a well-defined role and only communicates with neighbouring layers, providing encapsulation and separation of concerns."
- Draw (diagram to draw): draw five horizontal rectangles stacked. Label from top to bottom: Presentation (UI), Application/Service, Domain/Business Logic, Data Access, Database. Draw arrows only down and up between adjacent layers. Annotate: "Calls/uses" arrow downward, "returns/results" arrow upward.
Client–server architecture (defined): a style where functionality is split between clients (requesters of services) and servers (providers of services). Clients initiate requests; servers listen and respond. Two-tier client–server is the classic form (clients + central server). Assumptions: networked environment, server centralisation. Variants: thin-client (UI only) and thick-client (some business logic on client).
- Draw: a box labelled Server on the right, multiple small boxes labelled Client on the left. Draw arrows from each Client to Server and back. Annotate: "request/response over network (e.g., HTTP)".
Microservices architecture (defined): a style where the system is decomposed into small, independently deployable services, each owning a bounded context and typically its own data storage. Services communicate over lightweight protocols (HTTP/REST, gRPC, message brokers). Assumptions: high operational maturity (automation, monitoring), teams aligned to services, and eventual consistency is acceptable for distributed data.
- Exact statement: "Microservices decompose a system into small autonomous services, each responsible for a single business capability and independently deployable and scalable."
- Draw: several small rounded boxes (Service A, B, C). Each box has its own small cylinder labelled DB. Draw arrows between services labelled REST/gRPC or message bus. Optionally show an API Gateway box in front.
Model–View–Controller (MVC) (defined): an architectural pattern for interactive applications that separates responsibilities into Model (data and business rules), View (UI), and Controller (handles input, updates Model and selects View). Assumption: single application process (common in web or desktop apps) though MVC can be adapted to distributed systems.
- Draw: three boxes labelled Model, View, Controller arranged in a triangle or sequence. Draw arrow from Controller to Model (updates), Model to View (data), View to Controller (user input). Annotate typical flow: User -> View -> Controller -> Model -> View.
Comparisons and trade-offs (exact, exam-style):
- Layered vs Client–server: Layered is about logical organisation inside a system; client–server is about distribution between roles. A client–server system can implement a layered architecture on the server side.
- Client–server vs Microservices: Client–server centralises services on one or few servers; microservices distribute functionality into many autonomous services. Microservices increase deployment complexity but improve independent scaling and team autonomy.
- Microservices vs Layered: Microservices decentralise data and logic per service; layered keeps centralised layers and shared data. Choose microservices when fast independent deployments and heterogeneous tech stacks matter; choose layered for simpler systems and clear separation inside a single deployable unit.
Quality attributes mapping (short list students should memorise):
- Modifiability: layered and microservices are good (layered for code separation, microservices for isolated changes).
- Scalability: microservices and client–server (with horizontal scaling) are good; layered alone does not imply distribution.
- Testability: layered helps unit testing; microservices require contract and integration testing.
- Operational complexity: microservices > client–server > layered.
When to use which (rules of thumb):
- Use layered: small-to-medium systems, strong need for clear separation and simple deployment.
- Use client–server: interactive networked applications with centralised servers (e.g., traditional web apps).
- Use microservices: large systems with independent teams, need for independent scaling, or polyglot stacks.
- Use MVC: UI-centred applications where separation of UI, input handling and data model simplifies maintenance.
Formulas
For architecture topics we keep a short list of syntax and conventions to remember:
HTTP methods: GET, POST, PUT, PATCH, DELETE, HEAD, OPTIONS — standard verbs for REST; GET/HEAD/OPTIONS are safe; PUT and DELETE are idempotent; POST and PATCH are generally not idempotent; no units; used in client–server and microservices HTTP APIs.
Common ports: 80 (HTTP), 443 (HTTPS) — network ports used for web traffic.
API Gateway pattern: client -> API Gateway -> microservices — sequence to draw for request routing, authentication/authorization, and rate limiting.
Database-per-service: each microservice owns its database (logical ownership, not always a separate physical server) — design rule, not a numerical formula.
Worked examples
Design a layered architecture for an online bookstore (exam-style answer):
- Step 1 (requirements): UI for browsing, search, shopping cart, order processing, inventory, and payments.
- Step 2 (layers): draw 5 layers as earlier: Presentation (web pages / mobile UI), Application (session and cart services), Domain (book catalog, order, payment business rules), Data Access (ORM, repositories), Database (catalog DB, orders DB).
- Step 3 (explain interactions): Presentation calls Application APIs (HTTP/local), Application invokes Domain methods, Domain uses Data Access to persist/retrieve. Data Access uses SQL to connect to Database.
- Step 4 (advantages): clear separation makes swapping DB easier, unit testability of Domain layer, UI changes limited to Presentation.
- Step 5 (limitations & mitigation): single deployable server may be a bottleneck; mitigate by splitting Application into services (move toward microservices) or tiered servers.
Compare client–server and microservices for a ride-hailing app (model answer):
- Client–server approach: mobile app (client) talks to a central server that hosts matching, pricing, payments. Pros: simpler deployment, single codebase for server. Cons: bottleneck; harder to scale parts independently.
- Microservices approach: decompose into services: Rider Service, Driver Service, Matching Service, Pricing Service, Payment Service. Each service has own DB. Use API Gateway and message broker for asynchronous events (driver location updates). Pros: independent scaling (matching high load), independent deployments, teams own services. Cons: complexity: inter-service communication, distributed transactions (use eventual consistency), more operations work (CI/CD, monitoring).
- For exam: include diagram: mobile clients -> API Gateway -> services (boxes) -> individual DBs; show message broker for events.
Trace MVC flow for a simple login in a web app (step-by-step trace expected in exams):
- Step 1: User enters credentials on Login View and submits (HTTP POST to /login).
- Step 2: Controller receives POST, validates input, calls Model (UserAuth) to check credentials.
- Step 3: Model queries user repository (Data Access) and returns result (success/failure).
- Step 4: Controller interprets result: on success set session and select Home View; on failure select Login View with error message.
- Step 5: View renders HTML and sends response to browser.
Common mistakes
- Claiming "every microservice must have its own physical database server" — inaccurate. The rule is ownership of data (logical), not necessarily separate physical machines.
- Ignoring operational overhead of microservices in answers (students list only benefits).
- Mixing MVC flow arrows in diagrams (draw the exact flow: Controller -> Model -> View, and View -> Controller for user events).
- Saying client–server is obsolete — it is still widely used (web, APIs); microservices are an evolution for certain needs.
For your exam
Types of questions you will get and what full-mark answers include:
- Definitions (short): define each architecture style clearly, state core constraint and one key quality attribute it supports.
- Short notes: write advantages and limitations, include one diagram (draw and label boxes and arrows as described above).
- Compare and contrast: give a table or bullet list comparing scalability, deployment complexity, team organisation, data management.
- Design question (long): given requirements, produce an architecture choice, draw the diagram, justify choice with quality attributes and discuss trade-offs and migration steps.
- Trace/sequence question: trace an MVC or client–server request; include each step, where code runs, and where state is stored.
- Practical/programming: list HTTP methods for REST API design and sketch endpoints for a sample service.
Full-marks answers must:
- Use correct definitions (bold terms mentally or explicitly in answer),
- Provide a clear labeled diagram (draw boxes, arrows and labels as described in the Key ideas section),
- Explain trade-offs and not just list pros,
- Mention data ownership and consistency trade-offs for distributed systems,
- Include operational concerns (monitoring, CI/CD, fault isolation) for microservices.
Quick check
- What is the main constraint of a layered architecture?
- Name two communication protocols commonly used between microservices.
- In MVC, which component is responsible for handling user input?
Answers: 1) Layers communicate only with adjacent layers (separation of concerns). 2) HTTP and gRPC (also AMQP/Kafka via message brokers). 3) Controller.
Finished this topic? Mark it so your progress, study plan and readiness keep up.
Stuck on something here?