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.
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(n⋅m) connections into…? ::: 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.
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.