Course contentsShow
← Databases & SQL
Lesson 1236 of 1,95311. NoSQL and Document ModelsFree lesson

Load Testing Document Systems

Create realistic synthetic workloads to validate schema design under stress.

In this lesson, you will learn how to design synthetic workloads to validate your document schema’s performance under heavy stress.

When you denormalize data in a document store, your schema design often hinges on specific access patterns. However, a design that performs well with 10,000 documents might degrade exponentially as your collection grows or as concurrency increases. To validate your design, you must create a "synthetic workload"—a controlled script that mimics the behavior of real users.

Defining the Workload Mix

A realistic test is not just about raw write speed; it is about the ratio of operations. If your application typically performs 90% reads and 10% writes, your load test must mirror that proportion.

To simulate this, write a script that executes a loop of operations using your application's expected query profile:

// Example: Simple synthetic workload script
const runTest = async (opsCount) => {
  for (let i = 0; i < opsCount; i++) {
    const action = Math.random();
    if (action < 0.8) {
      // Simulate read-heavy pattern
      db.users.find({ status: "active" }).limit(10);
    } else {
      // Simulate writes
      db.users.updateOne({ _id: targetId }, { $set: { lastActive: new Date() } });
    }
  }
};

Stressing the Schema

Beyond the ratio, you must test for bottlenecks specific to document databases:

  1. Document Growth: If your schema uses unbounded arrays (e.g., storing a list of user comments inside the user document), synthetic tests should include documents that have already "grown" to their maximum expected size to see how it impacts memory and fragmentation.
  2. Concurrency under Write Concern: Test your system using different Write Concern levels. If your production environment requires high consistency, your load test must verify that the latency introduced by waiting for replicas to acknowledge writes remains within your SLO (Service Level Objective).
  3. Index Saturation: Run your workload while the dataset is larger than your available RAM. This forces the system to perform disk I/O, revealing if your indexing strategy is efficient enough to prevent the "read-from-disk" penalty from collapsing your throughput.

By injecting these synthetic bursts, you can identify if your chosen shard key is causing hotspots or if your denormalized structure requires too many fragmented writes before the system even hits production.

Key Takeaway: A successful load test doesn't just measure total throughput; it validates that your schema maintains consistent latency under the exact ratio of reads and writes expected in your production environment.