Senior
Is it possible to store only order_id -> current_status in Redis, and read the full order card from a replica? How to separate these two types of reads?
sobes.tech AI
Answer from AI
Yes, it is possible to store only the mapping of order_id -> current_status in Redis, and read the full order card from the database replica. This approach allows for quick retrieval of the current order status from Redis, minimizing delays, while using the replica for more heavy queries with full information.
To separate the two types of reads, you can:
- Use different services or layers in the application: one responsible for quick access to status via Redis, another for obtaining full information from the replica.
- Clearly separate requests in the API or business logic: status requests go to Redis, full card requests go to the replica.
- Cache only the data in Redis that changes frequently and is needed quickly, and fetch other data from the replica.
Example:
// Getting status from Redis
status, err := redisClient.Get(ctx, orderID).Result()
// Getting full order card from the replica
orderCard, err := replicaDB.QueryOrder(orderID)
This approach improves performance and reduces load on the primary database.