0

I'm learning how to structure and query data of a social media application where all the posts are stored in PostgreSQL. Every post has some meta data that can be huge but only a portion of it will be showed in the user feed, for example imageURL, title. Every user has friends that are linked in PostgreSQL. Im trying to see what is the best way to implement a user feed with Redis.

  1. if redis is storing only postID's in the user feed, should it also store post information as a different hash table and after getting the user feed get all the post information from the hash table

  2. or after getting the postID's from the user feed, query Postgres for the posts before returning to user.

What is more scalable, economical and efficient solution or is there a completely different way to approach this?

j.doe
  • 305
  • 3
  • 16

1 Answers1

0

If i were you, I would do approach #1. But the only way to make sure is to benchmark.

Why don't you use ab or a similar tool to bench and see it for yourself?

Tuan Anh Tran
  • 6,807
  • 6
  • 37
  • 54
  • I missed one part the post data is also in elastic. Would it be a good idea to fetch those id's from elastic instead of making a seperate hash table and why queries on postgres is a bad idea – j.doe Dec 13 '19 at 01:06
  • the reason i prefer redis over postgres is scaling redis is a lot easier than scaling postgres. again, regarding loading from ES or caching in redis, you should always bench. the workload and use case is different for each person. – Tuan Anh Tran Dec 13 '19 at 01:56
  • ok that makes sense but lets say you are just starting off your project and you have no traffic or a lot data that would give meaningful benchmarks. Which approach of the three would you pick. taking into consideration if the data is already in elastic – j.doe Dec 13 '19 at 02:27
  • if i were you, i would just load from ES. cache it only when performance problem arise with ES – Tuan Anh Tran Dec 13 '19 at 05:38