Computer Engineering is coming soon

We're still writing and reviewing the notes for every subject, and we'll open it when every subject is ready. Meanwhile you can practise aptitude, ask Aria about any subject, or see the branches that are ready.

Architectural styles and middleware

Architectural styles describe recurring structural patterns for distributed systems; middleware is the software layer that implements communication and integration, chosen to match the style and non-functional goals.

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

Two or three sentences: where an engineer uses this.

Architectural styles give engineers a reusable blueprint to organise distributed systems so they meet goals like scalability, reliability and maintainability. Middleware is the software glue that implements communication, data exchange and common services — engineers choose middleware to realise an architecture (for example to implement a client–server or publish–subscribe system) and to satisfy quality attributes such as latency, throughput and interoperability.

Key ideas

Explain plainly, define each term before using it; give exact statements and assumptions.

  • Architectural style — a precise definition: an architectural style is "a family of systems characterised by a pattern of structural organisation". More concretely: it is a set of named, coordinated constraints on the elements and relationships of software architecture (components, connectors, and rules). Assume components are computational units and connectors are interaction mechanisms.

  • Middleware — a precise definition: middleware is software that provides general-purpose services and communication abstractions above the operating system and below application code, enabling distributed components to interact without each implementing low-level networking. Assume middleware runs on the hosts that participate in the distributed system.

Important recurring architectural styles used in distributed systems (each defined and assumptions stated):

  • Client–server: a style with two classes of components, clients (requesters of services) and servers (providers of services). Constraint: communication initiated by clients to servers; servers listen and reply. Assumes clients and servers may be distinct hosts or processes and that the network supports point-to-point communication.

    • Typical diagram to draw: draw two boxes labelled Client and Server, arrow from Client to Server labelled "request", arrow back labelled "response", and indicate a network cloud between them.
  • Layered architecture: arrange components into horizontal layers; each layer provides services to the layer above and uses services of the layer below. Constraint: interactions only between adjacent layers (unless exceptions allowed). Assumes clear separation of concerns and stable interfaces.

    • Diagram to draw: stack of 3–5 horizontal boxes; label each layer (e.g., Presentation, Business Logic, Data Access), draw arrows only between adjacent boxes.
  • Broker (or message broker): components (clients and servers) interact through a broker component that mediates requests, routing, and translation. Constraint: decoupling of clients and servers; broker may provide persistence, transformation, discovery. Assumes trust in broker and acceptable centralisation or replicated brokers.

    • Diagram: multiple clients and servers connected only to a central broker box.
  • Publish–subscribe: publishers send messages to a topic or event channel; subscribers receive messages for topics they subscribe to. Constraint: publishers and subscribers are decoupled (no direct knowledge). Assumes existence of reliable or best-effort event distribution service (middleware implements this).

  • Peer-to-peer (P2P): all nodes (peers) have similar roles and can act as client and server. Constraint: decentralised control, distributed data and lookup. Assumes routing overlays or gossip protocols for discovery.

  • Microkernel (a.k.a. plug-in) architecture: a minimal core (the microkernel) provides basic services; optional services are implemented as plug-ins interacting with the kernel. Assumes small trusted core and dynamic extension capability. Do not confuse this with OS microkernels; here it refers to a software architecture pattern for modular systems.

  • Service-Oriented / Microservices: system decomposed into independent services communicating via well-defined APIs (often over HTTP/REST or messaging). Constraint: services are independently deployable and loosely coupled. Assumes networked communication and a service discovery mechanism.

Middleware types, defined and contrasted (exact definitions):

  • Remote Procedure Call (RPC) middleware: provides a programming model where a procedure in a remote process can be invoked as if local. It uses stubs (client and server), marshalling (serialising parameters), and binding (finding remote endpoint). Assumes synchronous invocation semantics unless otherwise specified.

  • Message-Oriented Middleware (MOM): provides asynchronous message queues/topics; producers send messages to middleware, consumers receive messages later. Assumes decoupling and possibly persistent storage.

  • Object Request Broker (ORB): middleware implementing distributed objects; provides object location, invocation, and lifecycle management (example model: CORBA-style). Assumes object identity and interface definition languages (IDL).

  • Database middleware / Transaction monitors: provide distributed transaction coordination, two-phase commit, and connection pooling. Assumes ACID semantics where used.

  • Remote Method Invocation (RMI): an object-based RPC with object identity and reference semantics (often language-specific).

Key trade-offs and non-functional properties (clear statements):

  • Coupling vs. scalability: Tight coupling (synchronous, temporally coupled RPC with strict interface dependencies) simplifies programming but can reduce scalability and resilience. Loose coupling (MOM, publish–subscribe) improves scalability and availability but can increase complexity for consistency. Here, loose coupling means reduced assumptions about time (asynchronous), location (no direct endpoint knowledge), and interfaces (schema/version tolerance).

  • Centralisation vs. decentralisation: Centralised brokers simplify coordination and management but may be a single point of failure and bottleneck. Decentralised P2P architectures improve fault tolerance and scale but complicate discovery and consistency.

  • State location: Stateful services can improve performance (cache locality) but need replication/consistency protocols; stateless services are easier to scale.

  • Consistency vs availability under partitions (CAP): In the presence of network partitions, a system cannot simultaneously provide both strong consistency (e.g., linearizability) and availability; architectures and middleware choose CP or AP trade-offs and may offer tunable consistency.

Design rules of thumb: choose the style that matches the dominant system requirement (e.g., low latency → client–server or RPC with local caching; high scalability and loose coupling → publish–subscribe or microservices with asynchronous messaging).

Formulas

Each formula on its own line; symbols explained, units.

L = λ · W

  • L = average number of items in system (dimensionless, count), λ = arrival rate (items·s⁻¹), W = average time in system per item (s). Applies when system is stable and Little's law conditions hold (stationary averages, FIFO not required).

ResponseTime_one_way = T_transmission + T_propagation + T_processing + T_queuing

  • T_transmission = message size (bits) / bandwidth (bits·s⁻¹), unit: s; T_propagation = distance (m) / signal speed (m·s⁻¹), unit: s; T_processing, T_queuing in s. Applies to a single one-way packet/message.

ResponseTime_RPC ≈ 2·(T_transmission + T_propagation) + T_processing_client + T_processing_server + T_queuing_client + T_queuing_server

  • For an RPC round-trip, include both request and reply paths (two transmissions and two propagations) plus processing and queuing on both ends; units: s.

Throughput_max = 1 / ServiceTime (upper bound for a single-server)

  • Throughput in items·s⁻¹, ServiceTime in s/item. Applies when the server is the bottleneck and kept busy (saturated); actual throughput ≤ 1/ServiceTime.

Utilization ρ = λ · S

  • ρ (dimensionless, 0≤ρ<1 for stability), λ arrival rate (items·s⁻¹), S average service time (s). Applies to single-server queuing models; ρ<1 required for steady-state.

Note: these are queueing-related formulas often used to reason about middleware performance.

Worked examples

Two or three university-exam standard examples.

Example 1 — Design choice and justification (short-answer exam style): Question: For an online chat application with many concurrent users, low latency, and the requirement that messages reach subscribed users even if some nodes disconnect, choose an architectural style and middleware and justify. Model answer (step-by-step):

  1. Requirements: low-latency delivery, many concurrent users, resilience to node churn, message fan-out to subscribers.
  2. Architectural style: publish–subscribe fits because it decouples publishers and subscribers; it supports fan-out and can deliver to many subscribers efficiently.
  3. Middleware: use a distributed publish–subscribe broker or a topic-based MOM (with persistent topics) to ensure messages for disconnected subscribers are stored and delivered later.
  4. Justification: publish–subscribe gives loose coupling and scalability; persistence in middleware ensures delivery despite node disconnects; brokers can partition topics to scale.
  5. Trade-offs: brokers may be scaled or replicated to avoid single point of failure; eventual consistency acceptable for chat history but critical notifications might need stronger guarantees. Final: choose publish–subscribe with replicated brokers and persistent topics — state why each decision maps to a requirement.

Example 2 — RPC call trace (algorithmic trace): Question: Show the sequence of actions when client C calls remote procedure f(x) on server S using RPC middleware. Trace (step-by-step):

  1. Client calls local stub f_stub(x).
  2. Client stub performs marshalling: serialise x into a message buffer.
  3. Stub executes binding: look up server address (from registry or cached binding).
  4. Stub sends message across network (system call -> OS -> NIC).
  5. Network delivers message to server host; server OS passes to server RPC runtime.
  6. Server RPC runtime unmarshalls parameters, calls server-side stub which invokes actual function f(x).
  7. Server computes result r and server stub marshalls r into reply message.
  8. Reply sent back to client; client RPC runtime receives, unmarshalls, returns r to client code. Explain timings with the ResponseTime formula and note failure handling: timeout and retries may be used if no reply. For RPC round-trip latency, include both request and reply paths; retries require idempotent operations or duplicate suppression — exactly-once semantics are not generally achievable without coordination.

Example 3 — Numerical latency calculation: Given: message size = 10 000 bits, bandwidth = 10 Mbps (10·10^6 bits·s⁻¹), distance = 5000 km (5·10^6 m), signal speed in fibre ≈ 2·10^8 m·s⁻¹, processing = 2 ms, queuing ≈ 1 ms. Steps:

  • T_transmission = 10 000 / (10·10^6) = 0.001 s = 1 ms.
  • T_propagation = 5·10^6 / (2·10^8) = 0.025 s = 25 ms.
  • T_processing = 2 ms = 0.002 s.
  • T_queuing = 1 ms = 0.001 s.
  • ResponseTime_one_way = 0.001 + 0.025 + 0.002 + 0.001 = 0.029 s = 29 ms. Note: verify the signal speed in fibre and rounding (see verify list).

Common mistakes

What students actually get wrong in exams.

  • Confusing middleware with operating system services — middleware sits above the OS and provides distributed-system-level services.
  • Mixing architectural style and implementation detail (e.g., saying "RPC is an architecture" instead of a middleware style/communication mechanism).
  • Ignoring assumptions: giving Little's law answers without ensuring system stability (ρ<1) or stationarity.
  • Treating central brokers as automatically scalable without discussing replication and fault tolerance.
  • Forgetting to define terms like "loose coupling" or "marshalling" before using them.

For your exam

Kinds of questions and what full-marks answers include.

  • Definitions: define architectural style, middleware, RPC, MOM, publish–subscribe. Full marks: precise definition plus one-line example.
  • Short notes: compare client–server vs P2P, broker vs direct messaging. Full marks: list at least three differences and one diagram or scenario.
  • Derivations: use Little's law or response-time decomposition for a given scenario. Full marks: state assumptions, write formula, substitute numbers with units, and final answer with units.
  • Design questions: choose an architecture and middleware for given requirements. Full marks: state requirements, map to style and middleware with justifications and discuss trade-offs.
  • Diagrams: draw a layered architecture or broker system and label components and arrows. Full marks: clear labels, arrows showing interactions, and brief caption.

Quick check

Three short questions with answers.

  1. What is middleware? (one line)
  2. Name two differences between RPC and MOM.
  3. State Little's law.

Answers: 1) Middleware is software between OS and applications that provides distributed services (e.g., communication, naming, transactions). 2) RPC is usually synchronous and exposes procedure-call semantics; MOM is asynchronous and uses queues/topics for message exchange. 3) Little's law: L = λ · W (average items = arrival rate × average time in system).

Finished this topic? Mark it so your progress, study plan and readiness keep up.

Stuck on something here?