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

posée 3 months ago240 vuesen

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?

Diagnostic IA

Généré par IA. Ce n'est pas une réponse — la communauté ci-dessous le confirme ou le corrige. Vérifiez toujours avant de vous y fier.

posée 3 months ago

1 réponse

9
✓
✓ Réponse acceptée

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).

Connectez-vous pour dire si ça a marché.

answered 3 months ago

Sign in and verify your email to post an answer.