Tracing a Product Detail API Call Through Every Layer of a Spring Boot App
Most backend tutorials teach concepts in isolation; this walkthrough connects them into a single traceable chain. A developer who can follow a request from filter to JSON response can debug production issues across any layer without guessing.
A public product detail endpoint in a fullstack e-commerce project is dissected layer by layer, from the HTTP entry point through security whitelisting, Redis cache-aside logic, MyBatis-Plus database queries, and category table assembly into a response DTO. The walkthrough covers five cache states—HIT, MISS, NULL_HIT, DEGRADED, and BYPASS—and shows how each one dictates whether the request returns from memory, falls back to MySQL, or throws a business exception. Null value caching with a short TTL prevents repeated database hits for stable 404s, while Redis failures trigger degradation instead of hard errors.
The backend enforces visibility rules that the frontend never sees: anonymous users can only access products with an ON_SALE status, and a disabled category makes an otherwise valid product return a 404. A GlobalExceptionHandler catches business exceptions and wraps them into a unified JSON envelope containing a stable error code and a traceId, giving frontend developers a consistent contract to code against. The traceId, generated or propagated by a filter at the very start of the request, ties every log line from cache lookup to database query back to a single identifier.
A troubleshooting checklist and a set of curl-and-Redis verification steps turn the theory into a repeatable debugging workflow. The chapter closes by contrasting the detail endpoint's simple Redis key with the list endpoint's deliberate lack of caching, showing that not every read deserves a cache.
Teaching backend development by tracing a single request end-to-end mirrors how senior engineers actually onboard onto a new codebase—they follow the data, not the class hierarchy.
The distinction between security rules (who can call an endpoint) and business visibility rules (what data the endpoint returns) is a recurring source of bugs that this walkthrough makes explicit.
Null value caching is an underappreciated pattern: it prevents cache penetration attacks on non-existent IDs while keeping the cache layer's abstraction clean.
Returning a DTO instead of a database entity is not just an architectural nicety; it prevents frontend code from coupling to table schemas that change independently.
The traceId pattern, trivial to implement with a single filter, solves the perennial problem of correlating a user's vague bug report with a specific backend request.