Pick the fix
Where should the rule 'an order can't be refunded after 30 days' live?
Hint 1 of 1
Which layer do all entry points share?
Choose an answer, then open Show answer below to check it.
Text version
API:
- Parse the JSON body and reject unknown fields: Input validation is the HTTP boundary's job, before any rule runs.
- Return 404 vs 409 for an error: Mapping outcomes to status codes is HTTP-specific, so it stays at the edge.
- Check the caller's token and scopes: Authentication happens before the request reaches business code.
Service:
- Rule: refunds only within 30 days: A business rule every entry point must obey, so it lives in the domain layer.
- Reserve stock and create the order as one unit: The service defines the unit of work and opens the transaction around it.
- Decide which email to send after checkout: Choosing the next business step is orchestration, not HTTP or SQL.
Data:
- SELECT the order with its items in one query: Queries live in repositories so services never see SQL.
- Map a database row to an Order object: Row-to-object mapping is the data layer's boundary work.
- Read-through cache for product lookups: Caching is a detail of how data is fetched; services just ask for products.
Infra:
- Ship logs and traces to the collector: Observability plumbing is shared infrastructure, not business logic.
- Load DATABASE_URL at startup: Configuration is supplied by the environment the service runs in.
- Drain requests on SIGTERM: Process lifecycle belongs to the runtime and deployment platform.
Show answer
Answer: A In the service (domain) layer
Correct. It's a business rule every entry point must respect.
Business rules belong where every caller has to pass through: the service layer. HTTP handlers, queue consumers and admin scripts all call it, so the 30-day rule can't be bypassed.
Why not the others?
- B In the HTTP handler. A queue consumer or admin tool would bypass it.
- C In the SQL query only. Hidden, hard to test, and the error message is lost.
- D In the load balancer. Infrastructure doesn't know about refunds.