Skip to content

Conversation

@stephenliang
Copy link
Member

@stephenliang stephenliang commented Nov 14, 2025

Currently, the redis cache handler is reading and writing from the primary endpoint which is causing throttling from the primary instance. Instead, reads should come from read-only replicas and writes go to the primary. This changes the caching pattern to eventual consistency, but this is acceptable for the marketing sites.

  • Added separate read and write handlers for Redis caching.
  • Updated constructor to initialize handlers based on environment variables.
  • Modified methods to use new handlers for cache operations.

Verified on https://csforall.marketing-sites.test-code.org/

Currently, the redis cache handler is reading and writing from the primary endpoint which is causing throttling from the primary instance. Instead, reads should come from read-only replicas and writes go to the primary. This changes the caching pattern to eventual consistency, but this is acceptable for the marketing sites.

- Added separate read and write handlers for Redis caching.
- Updated constructor to initialize handlers based on environment variables.
- Modified methods to use new handlers for cache operations.
@stephenliang stephenliang requested a review from Copilot November 14, 2025 00:28
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR implements separate read and write handlers for Redis caching to reduce throttling on the primary Redis instance. Reads are now directed to read-only replicas while writes go to the primary endpoint, implementing an eventual consistency pattern suitable for marketing sites.

Key changes:

  • Split Redis connection into separate read and write endpoints using environment variables
  • Refactored cache handler to use dedicated handlers for read and write operations
  • Updated infrastructure configuration to provide both primary and reader endpoint URLs

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
apps/marketing/cicd/3-app/template.yml.erb Updated environment variables to provide separate Redis read and write endpoints
apps/marketing/cache-handler.mjs Refactored cache handler class to use separate read/write handlers with new endpoint configuration

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

const isRedisCacheEnabled =
process.env.REDIS_URL && process.env.NODE_ENV === 'production';
process.env.REDIS_READ_URL &&
process.env.REDIS_WRITE_URL &&
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might (or not?) be worth warning if only one of these is set, as I could see only setting one and expecting redis to be enabled. Very much your call.

@stephenliang stephenliang merged commit 10cb8d2 into main Nov 14, 2025
74 of 78 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants