Support Dual Write to the container registry redis clusters
Context
The GitLab Container Registry currently uses two separate Redis clusters:
- A legacy cluster used by the Redis cache
- A newer cluster used for database load balancing
Following the work in epic gitlab-com/gl-infra/data-access/durability#24 (closed), the registry will consolidate to a single dedicated Redis cluster (the newer one currently used for database load balancing). This migration requires implementing a dual-write approach to ensure data consistency and minimize risk during the transition.
Implementation Requirements
-
Interface Abstraction
-
Create a CacheInterfacethat abstracts currentCacheoperations
-
-
Dual-Write Capability
-
Implement DualWriteCachethat satisfiesCacheInterface -
Support simultaneous writes to both Redis clusters -
Handle secondary write failures gracefully (non-blocking - via warn logs)
-
-
Feature Flags
-
Read Control FF: Toggle between primary/secondary for reads -
Dual-Write FF: Enable/disable dual-write functionality
-
-
Code Updates
-
Fix all code directly referencing concrete Cachetype to now referenceCacheInterface -
Use the DualWriteCacheimplementation of theCacheInterfacefor the redis cache operations only -
Update tests and code paths to work with interface
-
-
New Tests
-
Verify dual-write functionality -
Test read switching behaviour -
Validate error handling scenarios
-
With the implementation above we can enable a phased migration approach: first writing to both clusters, then switching reads to the new cluster, and finally disabling writes to the old cluster after validation.
After successfully migrating to the new Redis cluster, we'll need a follow-up issue to streamline our configuration and remove the dual write code. This should consolidate our Redis settings to reference a single Redis configuration rather than maintaining separate configurations for cache and database load balancing.