MongoDB or PostgreSQL for a Q&A or social app?

asked 3 months ago239 viewsen

6

My data looks like JSON (users, posts, comments, likes), so MongoDB seems natural. Friends say to use Postgres. What are the real trade-offs?

AI diagnosis

AI-generated. Not an answer — the community below confirms or corrects it. Always verify before relying on it.

asked 3 months ago

1 Answer

9
✓
✓ Accepted answer

Social and Q&A data is actually highly relational: users ↔ posts ↔ comments ↔ votes ↔ tags, plus follows, notifications and reputation. You'll constantly query *across* those relationships ("questions with tag X that the user hasn't voted on, sorted by score"). That's where relational databases shine.

PostgreSQL gives you joins, foreign keys (no orphaned comments), unique constraints (one vote per user), transactions across tables, and JSONB for the genuinely flexible parts.

MongoDB is strong when data is naturally document-shaped and read as a whole (product catalogs with varying attributes, event logs, CMS content), or when you need its horizontal-scaling model.

For a Q&A app, Postgres is the better default. It's exactly what Stack Overflow-style systems rely on (Stack Overflow itself runs on SQL Server).

Sign in to tell others whether this worked.

answered 3 months ago

Sign in and verify your email to post an answer.