practicajs / practica

Node.js solution starter boilerplate that is production-ready, packed with ✅ best practices and built with simplicity in mind
https://practica.dev/
MIT License
1.49k stars 136 forks source link

Add Redis functionality and library #153

Open goldbergyoni opened 2 years ago

goldbergyoni commented 2 years ago

🎯 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:

marcosmol204 commented 2 years ago

@goldbergyoni I want to take it. So, we want to create a cache layer that use redis therefore I am creating a cache library?

marcosmol204 commented 2 years ago

@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 ?

goldbergyoni commented 2 years ago

@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?

  1. About lru - To my understanding, it's in-process cache which is not as useful and scalable as cross-process cache
  2. 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

marcosmol204 commented 2 years ago

@goldbergyoni Yes, you can present me good first issues with higher priorities.

goldbergyoni commented 2 years ago

@marcosmol204 Just got back from a trip, back on track

I would suggest one of these 3 issues:

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

Poseidon-G commented 1 year ago

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.