I am managing a Rails application on Postgres through Heroku.

Let me implement much like Facebook "likes" on my small site for a number of products, for example user comments. What is the wisest method to store these during my database that'll be efficient and fast?

The apparent the first is just to possess a like join table between customers and products, something similar to this:

user_id int
item_id int
item_type string
created_at datettime

However, when being displayed, this could mean each time I pull a product, I would need to pull a join over the entire like table, that could end up with large.

The apparent response for this is to keep a counter within the products, for his or her ongoing like count. However, this will not work because who loved a product matters, for both display near the item, also to hide so on button for things a person has loved.

My plan's to increase all pleasant products a text area by which I'd store a serialized array. This way, every pull of the item would include the entire listing of who loved it. It is possible to better method of doing this, or perhaps is this the suggested approach?

Have you got reason to think that the dataset will probably be so large the join will probably be too costly? Postgres, while a lot slower because the quickest RDBMSs available, is fairly fast nowadays. I did previously operate a website that got countless pageviews each day, and needed some pretty complicated queries to create each page. By doing a little of simple caching we could run it on very modest hardware.

You allow up many of the advantages of choosing an RDBMS whenever you denormalize. I'd only achieve this basically understood I needed to. And when which were the situation I'd think about using another thing, just like a simple key/value database, for your data. However I believe that measuring only prone to be for you personally for those who have an awful large amount of data.