Postgres Hstore vs. Redis - performance wise

jribeiro picture jribeiro · Feb 5, 2012 · Viewed 19.6k times · Source

I read about HStores in Postgres something that is offered by Redis as well.

Our application is written in NodeJS. Two questions:

  • Performance-wise, is Postgres HStore comparable to Redis?

  • for session storage, what would you recommend--Redis, or Postgres with some other kind of data type (like HStore, or maybe even the usual relational table)? And how bad is one option vs the other?

Another constraint, is that we will need to use the data that is already in PostgreSQL and combine it with the active sessions (which we aren't sure where to store at this point, if in Redis or PostgreSQL).

From what we have read, we have been pointed out to use Redis as a Session manager, but due to the PostgreSQL constraint, we are not sure how to combine both and the possible performance issues that may arise.

Thanks!

Answer

Matt Sergeant picture Matt Sergeant · Feb 6, 2012

Redis will be faster than Postgres because Pg offers reliability guarantees on your data (when the transaction is committed, it is guaranteed to be on disk), whereas Redis has a concept of writing to disk when it feels like it, so shouldn't be used for critical data.

Redis seems like a good option for your session data, or heck even store in a cookie or in your client side Javascript. But if you need data from your database on every request then it might not be even worth involving Redis. It very much depends on your application.