skip to Main Content

I’m using a Map Object in my Node application to store the websocket information of the logged in users.

I realized that if I eventually use something like pm2 I would face issues as the values in a process’ Map Object won’t be accessible from another one.

The application itself doesn’t do too much heavy lifting. It’s an API endpoint, sending queries to the DB and returning the data to the client as it comes, so the need to scale horizontally seems also far away right now.

From the "tests" I did on a Map Object itself (iterating over a large Map Object on Firefox’s console) started feeling slow at 1 000 000 items, and my laptop specs are far from spectacular.

Besides the benefits of easier horizontal scaling and likely data shaping, would I be missing anything performance wise?

2

Answers


    • Redis used as aside cache when you want to speed up you query.

    You can store last db result to Redis, when new query comes, search from Redis first.

    • Redis comes when you want to scale your memory.

    If you Map Object is large and you machine is not enough for that. Redis will help you.

    Login or Signup to reply.
  1. Answering the question "When to use Redis instead of Map Object in javascript" – When you have to scale your app into multiple instances, you cant use Map object, because it only exists where you created it and be unaccessible for other instances.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search