Architecture
User Requests a Page: When a user requests a page from the Next.js app, the request is initially handled by the Next.js server.
Next.js Checks Redis Cache: When the user requests a page, the Next.js app first checks if the requested page exists in the Redis cache. It does so by querying the Redis cache with a specific key that represents the requested page.
Cached Page Exists: If the requested page is found in the Redis cache, Next.js retrieves the page data from the cache and sends it back to the user as the response (after preparing the correct HTML). This eliminates the need to make a request to the Drupal backend app, resulting in faster response times.
Cached Page Doesn't Exist: If the requested page is not found in the Redis cache, Next.js proceeds to the next step.
Next.js Requests Page from Drupal: Next.js sends a request to the Drupal backend app, asking for the data needed to render the requested page.
Drupal Fetches Data: The Drupal backend app receives the request from Next.js and sends the JSON response back to Next.js app.
Next.js Stores Page data in Redis Cache: Next.js caches the received JSON data in Redis for future use, so that subsequent requests for the same page can be served directly from the cache.
Next.js Sends Page to User: Finally, Next.js sends the rendered page as the response to the user's initial request.