awesome-everything RU
↑ Back to the climb

Backend Architecture

Middleware and DI: multiple-choice review

Crux Multiple-choice synthesis across the middleware and DI unit — the two axes, the middleware contract, injection scopes, the testing seam, and container resolution.
Your altitude — climbing toward senior
ZeroJuniorMiddleSenior
You are at senior altitude — in orbit
◷ 13 min

Six questions that cut across the whole unit. Each mirrors a judgement you make on a real backend — which axis a problem lives on, what the contract forbids, what lifetime an object should have — not a definition to recite.

Goal

Confirm you can place a problem on the right axis (request vs wiring), reason about middleware ordering and the response contract, choose an injection scope, and read a container failure — the synthesis the six lessons built toward.

Quiz

A handler is slow on every single endpoint, and separately a billing class is impossible to unit-test without hitting the real Stripe API. On which axis does each problem live?

Quiz

An Express middleware sends res.json(...) on a validation failure and then also calls next(). Under load it intermittently throws 'Cannot set headers after they are sent'. What rule was broken?

Quiz

A central Express error handler written as (err, req, res) never receives errors even though earlier code calls next(err). Why, and what is the fix?

Quiz

Intermittently, user A sees user B's account name. Auth is correct. A service registered as a singleton stores this.currentUser per request. What happened, and what is the cleanest fix?

Quiz

A behavior-preserving refactor splits one repo.save() into two saves inside a transaction. Final state is identical, yet forty tests go red. What does this reveal?

Quiz

An app boots in dev but crashes in prod with 'Nest can't resolve dependencies of UserService'. AuthService now imports UserService, which already imported AuthService. How do you read this, and what is the real fix?

Recap

The unit’s through-line is one habit: name the axis, then apply its discipline. The request axis (middleware) demands one ending per middleware and a deliberate order; error middleware needs four parameters. The wiring axis (DI) means classes declare needs and a composition root supplies them — default to stateless singletons, escalate scope only when forced, and read test pain as a design signal (mock the boundaries you don’t own, fake what you do). A container is that composition root mechanized: it topologically sorts the graph, refuses cycles, and should fail fast at boot. Every question here resolves back to those two axes and the cost each carries.

Continue the climb ↑Middleware and DI: free-recall review
shortcuts expand
search
K
prev piece
k
next piece
j
cycle tier
t
this menu
?
sources3
expand
  1. 01
  2. 02
  3. 03

Trademarks belong to their respective owners. Editorial reference only.