Layer and tier
A layer separates code responsibilities. A tier separates runtime deployment.
CMPE273 · Module 4
Compare layered systems, microservices, and event-driven systems through a campus marketplace. Design integration boundaries, contain failures, and develop a team project proposal.
A layer separates code responsibilities. A tier separates runtime deployment.
A cohesive responsibility with an owner, rules, and a contract.
A fact about a completed business change, with documented meaning.
An agreement about data meaning, ownership, trust, and failure behavior.
Components that can fail together because they share a dependency or resource.
flowchart LR U[HTTP handler] --> A[Checkout application] A --> D[Domain rules] A --> R[Repository] R --> DB[(Database)]
The handler parses a request. The application coordinates checkout, domain code checks rules, and the repository persists state. These calls may all run in one process.
flowchart LR
B["Browser tier"] -->|"Network request"| H
subgraph APP["Application tier: one running application"]
H["Request handling layer"] --> L["Business logic layer"]
L --> D["Data access layer"]
end
D -->|"Network query"| DB[("Database tier")] The three boxes inside the application are code layers using local calls. The browser, application, and database are deployment tiers connected by network calls. A layer does not need its own server.
flowchart TB UI[Marketplace client] --> O[Ordering] O --> I[Inventory] O --> P[Payments] O --> OD[(Order data)] I --> ID[(Stock data)] P --> PD[(Payment data)]
Ordering calls inventory and payments through contracts. Each service controls writes to its own data. Data ownership does not require a different database product for every service.
flowchart LR O[Ordering] --> I[Inventory] I --> P[Payments] O --> DB[(Shared tables)] I --> DB P --> DB
Direct access to shared tables couples schemas and business rules. A synchronous chain adds waiting and dependency failures without guaranteeing autonomy.
flowchart LR O[Ordering] -->|OrderConfirmed| B[Broker] B --> N[Notification consumer] B --> A[Analytics consumer]
Ordering publishes a fact. Each subscriber receives its own logical delivery and can process it later. Broker and subscription configuration determine actual delivery behavior.
flowchart LR O[Ordering] --> T[Local transaction] T --> D[(Order and outbox rows)] D --> R[Relay] R --> B[Broker] B --> C[Consumer]
The relay publishes committed outbox records and retries failures. A crash after publication can cause a duplicate, so consumers still need safe repeat processing.
stateDiagram-v2 direction LR [*] --> Pending Pending --> Reserved: stock reserved Reserved --> Confirmed: payment succeeds Reserved --> ReleasePending: payment declined ReleasePending --> Cancelled: stock released Reserved --> Reconciling: payment outcome unknown Reconciling --> Confirmed: charge found Reconciling --> ReleasePending: confirmed no charge
A decline can trigger stock release. An unknown payment outcome requires reconciliation before cancellation. Compensation is business work and can itself fail.
flowchart LR I[Inventory] -->|quantity in units| A[Supplier adapter] A -->|quantity in cases| S[Legacy supplier]
The adapter converts cases to units using an explicit pack size and maps supplier errors. A transport conversion alone does not resolve semantic differences.
flowchart TB subgraph H[One host] O[Ordering container] I[Inventory container] end O --> DB[(Shared database server)] I --> DB P[Payments on another host] --> DB
A host failure affects ordering and inventory. A shared database outage can also affect payments. Replicas in the same domain do not eliminate that shared risk.
flowchart LR P[Payment slows] --> W[Checkout workers wait] W --> Q[Requests queue] Q --> T[Clients time out] T --> R[Retries add load] R --> W
Payment latency holds workers. New requests and retries increase contention until checkout becomes unavailable, including requests that might not need payment.
Architecture decisions connect business requirements to runtime behavior.
A fictional marketplace sells student-made goods for campus pickup.
A boundary may separate code, deployment, ownership, or shared risk.
Discuss: Can two containers still share one failure domain? Name the dependency that makes your answer true.
Give request handling, business rules, and data storage separate jobs.
Only one hoodie remains. Maya and Leo both click “Buy.”
Several code layers can run together inside one application tier.
Discuss: If we add another application instance, which layers are copied with it? Does the database gain capacity too?
A modular monolith keeps catalog, ordering, and inventory organized within one deployment.
Four developers have six weeks to deliver the marketplace.
Discuss: Would twenty services improve this team’s ability to deliver? Explain the coordination and testing cost.
Each service owns its behavior and data access contract.
Put each rule where one service can enforce it reliably.
Discuss: Why is one service per database table often a poor business boundary?
A service boundary creates work for development and operations.
Separate services can still force teams to change and release together.
Discuss: Which boundary would you repair first: data ownership, a chatty API, or the deployment process? Explain your evidence.
An event reports a fact that consumers can handle independently.
Message names should expose the intended interaction.
Discuss: Does an OrderPlaced event prove payment succeeded? What must the contract say?
Order o42 is confirmed. A pickup-list worker receives event e17, then receives e17 again.
Discuss: What could go wrong if the worker saved e17 first, then crashed before adding the pickup entry?
An outbox stores a message alongside the order so it can be sent after the database commits.
A workflow records intermediate states and compensating actions.
Notification receives event e17, sends an email, and crashes before acknowledging.
Discuss: Which side effect requires a provider-supported idempotency key? What will you do when that support is absent?
Example: ordering asks payments to charge $25 for order o42.
An adapter protects marketplace semantics from a supplier’s representation.
Discuss: If pack size changes, which owner detects the mismatch and prevents incorrect stock?
Shared infrastructure can fail several otherwise independent services.
Waiting work consumes capacity in the caller.
Each control addresses a different mechanism.
A fallback must preserve the meaning of the user-visible result.
Discuss: Why is “payment succeeded” an unsafe fallback for a timeout?
Choose each interaction according to what the buyer needs before checkout can finish.
Discuss: If notification stops for ten minutes, what should the buyer see after a successful purchase?
Teams redesign the marketplace and test the design on paper.
Choose a user problem, then design a workflow that solves it.
Start with the people affected and the outcome they need.
Explain the decision and the evidence that could change it.
A defensible design explains both normal operation and recovery.
Discuss: Name one boundary you would change in your team’s design and the tradeoff you accept.
Use the linked references to challenge your architecture decisions.
Canvas remains the official source for project requirements, deadlines, submissions, and grading.
Draw, trace, challenge, and revise a marketplace design.