MongoDB 00:00:01 Can the shop confirm an order? A bookstore submits order forty-one to a MongoDB replica set with three voting data-bearing members. The driver sends the write to the primary. The shop now has a choice about the evidence required before it tells the buyer the order is accepted. The primary records the change and a secondary copies the operation from the replication log. In this example two voting members form a majority. Write concern describes what acknowledgement the client requested from the set. The third member can still be behind when a majority acknowledgement is returned. A reader choosing that member may see older data. Choose the read preference and read concern together with the promise made to the buyer. 00:00:46 An election changes the writer Now take order forty-two with acknowledgement from the primary alone. Suppose that primary fails before another member receives the operation. A buyer has heard success, but the surviving members do not yet have that write. The remaining eligible members can elect a new primary when they can obtain the required votes. A real driver's retry behavior depends on the operation and configuration. An interrupted request is not automatic proof that the order was cancelled. When the former primary returns, its divergent write may roll back as it rejoins. Majority acknowledgement and appropriate journaling settings change the durability contract. Ask what evidence the shop really needs to print a receipt. 00:01:34 Route by a customer's key Replication supplied extra copies. Sharding now distributes different ranges of orders across groups. A router uses placement metadata to decide which shard can answer a query. The shard key determines what that router can infer. Customer one hundred forty-two falls in the range one hundred through one hundred ninety-nine in our example. The router can send that lookup directly to shard B. The other shards need not spend time on it. Ask for all paid orders without the customer key. Multiple shards may hold matches, so the router gathers and merges results. A slow participant can now delay this query even when customer one hundred forty-two's own shard is quick. 00:02:21 Which key matches the bookstore? A status field containing only a few common values is a weak partitioning key by itself. Many orders have the same status. Adding machines cannot divide every repeated shard-key value into independently placeable groups. A monotonically increasing order date can concentrate new inserts at the newest range. Hashing identifiers can distribute inserts more broadly, but then a query lacking that identifier may visit more shards. Customer plus date can fit the bookstore's customer-history query if the distribution is healthy. Test the busiest customer separately. A reasonable average across customers does not prove that one huge account fits comfortably on a shard. 00:03:07 Grow the data model deliberately Start with a book review and ten short comments embedded in one document. A reader can fetch them together. Keeping the small collection with its parent matches how the page is read. A popular review can collect tens of thousands of comments. The document-size limit applies to the encoded document, including field and array overhead. A rough total of comment-text bytes alone is insufficient to show that it fits. Let each comment become a document keyed to the review. Index that reference and return one page at a time. Across the bookstore, the same design question recurs. What evidence confirms the write, what key routes the read, and which collection can grow without a bound?