DEV Community

Updating "denormalized" aggregates with "duplicates": MongoDB vs. PostgreSQL

In database-centric development, duplication of data is usually avoided due to potential update problems. Domain-Driven Design (DDD) embraces data duplication when aggregates own their data, focusing on controlled updates within aggregate boundaries. MongoDB supports this DDD approach with efficient updates on document arrays and fields, minimizing overhead. The provided example uses MongoDB to rename a player across many documents with a single `updateMany()` operation. This is more efficient for the read-heavy aggregate model. In contrast, PostgreSQL’s JSONB implementation often necessitates rewriting entire documents for similar updates, potentially making normalization more appealing. The core issue isn't duplication itself, but who owns the data and how updates are optimized. The example shows how MongoDB efficiently updates a player's name across tens of thousands of documents. The provided PostgreSQL example, however, shows a full rewrite of data. Thus, DDD denormalization is optimized by fine-grained MongoDB updates.
favicon
dev.to
dev.to
Create attached notes ...