4.5.5Software Engineering

Software architecture — layered, MVC, event-driven, microservices, serverless

2,498 words11 min readdifficulty · medium1 backlinks

WHY architecture matters at all

Figure — Software architecture — layered, MVC, event-driven, microservices, serverless

1. Layered (n-tier) architecture

WHY this shape? Because concerns change at different rates. The UI changes constantly; the database schema rarely. By separating them, a UI redesign doesn't touch persistence code.

HOW the rule works: dependencies point downward only. Presentation knows about Service; Service knows about Data; Data knows about nobody above it. This is "closed layers" — you cannot skip a layer.


2. MVC (Model–View–Controller)


3. Event-driven architecture


4. Microservices

Monolith Microservices
Deploy unit one many
Database shared per-service
Failure all-or-nothing isolated
Complexity in the code in the network/ops

5. Serverless (FaaS + managed backends)


Putting it together — Forecast-then-Verify


Recall

Recall Active recall — cover the answers
  • What two metrics does ALL architecture try to optimize? ::: low coupling, high cohesion.
  • In layered, which direction may dependencies point? ::: only downward.
  • In MVC, which component holds business rules? ::: the Model.
  • Event-driven turns O(nm)O(n\cdot m) connections into…? ::: O(n+m)O(n+m) via a broker.
  • Microservice boundaries are drawn around…? ::: business capabilities, each with its own database.
  • Serverless idle cost is approximately…? ::: zero (pay per invocation).
Recall Feynman: explain to a 12-year-old

Imagine building with LEGO. Layered is a cake — each floor sits on the one below and only talks to its neighbour. MVC is a puppet show: the puppet (Model) is the real thing, the stage (View) shows it, the puppeteer (Controller) reacts to the audience. Event-driven is a school bell: it rings, and whoever cares (lunch lady, teacher) reacts — the bell doesn't know who's listening. Microservices is many small food stalls instead of one giant kitchen — each cooks one dish and can open/close on its own. Serverless is renting a kitchen by the minute: you cook only when an order comes, pay only for those minutes, and someone else cleans up.


Flashcards

What is software architecture fundamentally deciding?
Where the boundaries go — which modules may depend on which — to keep the system changeable, testable, scalable.
Define coupling and cohesion and the goal for each.
Coupling = inter-module dependence (want low); cohesion = intra-module relatedness (want high).
In layered architecture, what is the dependency rule?
Each layer calls only the layer directly below it; dependencies point downward only.
Why is a layered app usually still hard to scale?
It typically deploys as one process (monolith); you replicate the whole stack, not one layer.
What are MVC's three components and their jobs?
Model = data+rules, View = renders, Controller = handles input and orchestrates.
What is the "fat controller" anti-pattern and its fix?
Putting business logic in the controller; fix is keeping controllers thin and logic in the Model/Service.
How does event-driven architecture reduce connection complexity?
From O(n·m) direct links to O(n+m) by routing through a broker; producers/consumers don't know each other.
What hard problem does event-driven architecture introduce?
Temporal coupling: eventual consistency, ordering, duplicates, hard distributed debugging.
Around what should microservice boundaries be drawn?
Business capabilities, each owning its own database — not technical layers.
Give two costs of microservices vs a monolith.
Network latency + distributed transactions, and operational cost of deploying/monitoring many services.
What is the recommended starting point before microservices?
A modular monolith; split out a service only when a boundary truly needs independent scaling/deployment.
What does serverless (FaaS) automate and how is it billed?
Auto-scales functions on demand from zero; billed per invocation × duration (GB-seconds).
Name three real limits of serverless.
Cold-start latency, execution time caps / statelessness, and vendor lock-in.
When does serverless cost beat a reserved server?
For bursty/low-volume workloads where idle cost (≈0) dominates; steady high volume favors reserved servers.

Connections

  • Coupling and Cohesion
  • Monolith vs Microservices
  • Message Queues and Brokers
  • Eventual Consistency
  • Conway's Law
  • Design Patterns — MVC, Observer
  • Scalability — Horizontal vs Vertical
  • Cloud Computing — IaaS PaaS FaaS

Concept Map

goal

lowers

raises

cost

style

style

rule

usually deploys as

separates

separates

separates

updates

selects

Software Architecture

Boundaries between code

Coupling low

Cohesion high

Indirection overhead

Layered n-tier

MVC pattern

Dependencies point down only

Monolith one process

Model data + rules

View renders UI

Controller handles input

Hinglish (regional understanding)

Intuition Hinglish mein samjho

Software architecture ka matlab hai: tum apne system ko kaise tukdo me kaato, aur kaunsa tukda kaunse dusre tukde ko jaan sakta hai. Asli goal sirf do cheez hai — coupling kam (ek module dusre par kam depend kare) aur cohesion high (ek module ke andar ki cheezein aapas me related ho). Har architecture style isi do cheez ko alag tarike se solve karti hai.

Layered ek cake jaisa hai — har floor sirf neeche wale floor se baat karta hai, dependency hamesha neeche ki taraf. Ye maintainability deta hai, par scaling apne aap nahi, kyunki pura app ek hi process me chalta hai (monolith). MVC UI ke liye hai: Model = data aur rules, View = sirf dikhana, Controller = user input lena aur Model update karna. Yaad rakho — business logic Controller me mat daalo, warna "fat controller" ban jata hai.

Event-driven me components ek broker ke through events bhejte hain. Producer ko nahi pata kaun sun raha hai, consumer ko nahi pata kisne bheja. Isse n×m connections O(n+m) ho jate hain — bahut teams ke liye scalable. Lekin debugging mushkil ho jati hai aur eventual consistency ka jhol aata hai. Microservices me poora system chhote-chhote services me toot jata hai, har service ka apna database, alag deploy, alag scale. Lekin chhoti team ke liye ye overkill hai — pehle ek achha modular monolith banao, zaroorat pade tabhi todo.

Serverless me tum sirf functions likhte ho, cloud provider unhe demand par chalata hai aur zero se scale karta hai — idle ka paisa nahi lagta, sirf jab chale tab. Spiky kaam ke liye best, par cold-start latency aur vendor lock-in jaise limits hain. Bottom line: architecture problem ke size ke hisaab se choose karo — bada hammer chhoti keel ke liye mat uthao.

Go deeper — visual, from zero

Test yourself — Software Engineering

Connections