practica
practica copied to clipboard
Add Redis functionality and library
🎯 Goal: - Add Redis to our flow and show how to use it properly. When querying for orders, we may cache an item in Redis for 1 minute. If it's already in the cache - we can serve it from there. If not, we try the DB and add to the cache (if found).
The deliverable constitutes (A) our own library that wraps a reputable redis client (B) Redis within our docker-compose (C) The change to the flow that were described above
🤔 Things to consider:
- Library decision - We may need to carefully pick between reputable libraries like ioredis and node-redis
- Create a wrapper library - Going with our existing architecture, the code is not approaching the redis client directly rather our own wrapper which itself is approaching the redis client (e.g., ioredis)
- Tests our library
- Prefer promisified version of clients
- Ensure the Redis connection/pool is a 'singleton' (no connection is opened for every interaction)
- Mind other Redis best practices, not necessarily in the 1st iteration
@goldbergyoni I want to take it. So, we want to create a cache layer that use redis therefore I am creating a cache library?
@goldbergyoni Some questions: If is a library cache. 1)What do you think about lru-cache in memory? 2)The library should export a middleware or a depency to be injected to some service ?
@marcosmol204 Handling Redis is a viable option, that said we have other priorities that should be addressed before caching. Shall I present you with a list of interesting contributions?
- About lru - To my understanding, it's in-process cache which is not as useful and scalable as cross-process cache
- The lib should expose a service that allows to set/get cache. It should not be coupled to Express (i.e. middleware)
You may see a POC here:
https://github.com/practicajs/practica/pull/173
@goldbergyoni Yes, you can present me good first issues with higher priorities.
@marcosmol204 Just got back from a trip, back on track
I would suggest one of these 3 issues:
- https://github.com/practicajs/practica/issues/83
- https://github.com/practicajs/practica/issues/144
- https://github.com/practicajs/practica/issues/158
OR
Replicate our data-access layer using Prisma. We want to evaluate whether Prisma is a good option, hence we should create the same data access layer code using it and then compare Sequelize vs Prisma
Whatever you choose, I'll be glad to elaborate via chat/talk and get you up to speed quickly
I think this feature will create libary and inject into services or controller before it get from DB. Should not be included as middleware will make the data in the general cache and if the data changes frequently, it is almost unusable.