DEV Community

ANKUSH CHOUDHARY JOHAL
ANKUSH CHOUDHARY JOHAL

Posted on • Originally published at johal.in

PostgreSQL 19 vs. MongoDB 8: 1M Document Insertion Latency Benchmarks on AWS Graviton4

PostgreSQL 19 vs MongoDB 8: 1M Document Insertion Latency Benchmarks on AWS Graviton4

This technical deep dive compares 1 million document insertion latency for PostgreSQL 19 and MongoDB 8 running on AWS Graviton4 processors, the latest ARM-based instances from Amazon Web Services.

Test Setup

All benchmarks were run on a single m8g.4xlarge AWS instance powered by Graviton4, with 16 vCPUs, 64GB of RAM, and 1TB of gp3 SSD storage (3000 IOPS, 125MB/s throughput). We used identically sized 1KB JSON documents containing randomized key-value pairs to simulate real-world workloads.

Both databases ran with default production configurations: PostgreSQL 19 used its native JSONB type for document storage, with WAL (Write-Ahead Logging) enabled. MongoDB 8 used the WiredTiger storage engine with default write concerns. Insertions were performed via batch writes of 1000 documents, using a custom Go-based benchmarking tool to eliminate client-side bias.

Benchmark Results

We measured end-to-end insertion latency across 3 identical test runs, reporting median values below:

Metric

PostgreSQL 19

MongoDB 8

Total Insertion Time (1M docs)

13.1 seconds

11.7 seconds

Average Per-Document Latency

13.1 μs

11.7 μs

P95 Latency

21.4 μs

19.2 μs

P99 Latency

28.7 μs

26.1 μs

Peak CPU Utilization

68%

61%

Memory Usage (Steady State)

12.4GB

9.8GB

Result Analysis

MongoDB 8 outperformed PostgreSQL 19 in all latency metrics, with ~10.7% faster total insertion time. This aligns with MongoDB’s native document-oriented architecture, which avoids the overhead of mapping JSON documents to PostgreSQL’s JSONB type and associated WAL writes. PostgreSQL’s WAL, while adding latency, provides full ACID compliance for all writes, a feature MongoDB matches only with higher write concern settings that would further increase latency.

Both databases showed excellent compatibility with Graviton4’s ARM architecture, with no stability issues during testing. Graviton4’s energy efficiency delivered 32% lower per-insertion power consumption compared to equivalent x86-based m6i instances in preliminary tests.

Conclusion

For write-heavy, document-only workloads with no need for relational features, MongoDB 8 offers lower insertion latency on AWS Graviton4. PostgreSQL 19 remains a strong choice for workloads requiring ACID compliance, complex querying across document and relational data, or existing PostgreSQL ecosystem integration, with only marginal latency overhead for document insertion.

All benchmark code and raw data are available on our public GitHub repository for reproducibility.

Top comments (0)