Operations Across Shops

A shopper’s cart and purchases belong to one shop, so our design keeps those operations within one shard. But suppose Shopend wants a report showing how many orders were placed yesterday across all shops. No single shard holds all of those orders.

Counting orders across shards

The Shopend API instance that runs the report sends every shard a request to count its orders from yesterday. It uses the same start and end times for each count. Each shard counts the orders it holds and returns its count. The API instance then adds the counts:

Shard Orders
A 1,200
B 800
C 1,000
Total 3,000

The API instance only needs the counts. It does not need to retrieve every order document to calculate the total.

Waiting for every shard

The API instance can send the count requests in parallel, but it must wait for every shard before returning a complete total. If shard C is slow, the report waits for C even after A and B have responded.

If C does not respond, the API instance may retry the request to C, fail the report, or return the count from A and B with a label that says clearly that the result is partial.

This report also uses database capacity on every shard. Each shard has to count its orders while handling its shops’ other database operations.