Skip to content
Advertisement

Creating a DB for comment sections with multiple page tags

I’m having a tough time choosing the correct database (SQL, NoSQL) for this use case even though it’s so common.

This is the main record –

Page:
Contains a number of fields (which will probably change and updated in the future).
Connected to a list of tags (Which can contain up to 50 tags).
Connected to a comment section.

Page records will be queried by using the tags.

In general, the reads are more important (so writes could be more expensive) and the availability should be high.

The reason not to choose mongodb style DB is because of the comment section, There are no joins, so the comment section must be embedded in the page and the document size could grow too much.
Also MongoDB is less reliant on availability (using CAP) and availability is important to me.

The reason not to choose SQL is because the scheme of the Page could be updated and there is no fixed scheme.
Also because of the tags system – another relational table should be created and as I understood, it’s bad for performance.

What’s the best approach here?

Advertisement

Answer

Take a look at Postgres and you can have the best of both.

Postgres supports jsonb which allows indexing of jsonb data types so your search by tags can be executed pretty efficiently, or keep them as an array data type.

If you concerned about the comments embedding, then link off to another table and benefit from joins which are first-class citizens.

Given your use-case, you could have a Pages table with main, well known columns and a few foreign keys to Authors etc, tags as an array or jsonb column, some page attributes in jsonb and your comments in a separate Comments table with foreign key to Users and Pages.

Both Mongodb and Postgres and great choices.

PS, I have built far more on Mongodb than Postgres, but really impressed by Postgres after recent evaluation for a new project.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement