HeadlinesBriefing favicon HeadlinesBriefing.com

PgBench Tests MongoDB Foreign Data Wrapper Performance

DEV Community •
×

An experiment using PgBench to compare a native PostgreSQL database against a MongoDB Foreign Data Wrapper setup revealed an unexpected result. The FDW configuration, which routes SQL queries to MongoDB collections, outperformed the standard PostgreSQL baseline, achieving 4,922 transactions per second versus 4,085 tps.

The test was designed to stress lock contention, a known PostgreSQL challenge. By running 50 concurrent connections updating a single row, the native PostgreSQL setup showed higher latency from locking. MongoDB's storage engine, which avoids row-level locks, provided more consistent performance despite the added translation layer overhead.

This highlights a practical trade-off for developers: while FDWs add latency and limit transaction control, they can offer a performance bridge during migrations. The experiment, conducted on a MacBook Pro using Docker and a local MongoDB Atlas deployment, suggests that for high-contention workloads, the target database's architecture can outweigh the cost of a translation layer.