Document Databases

In this chapter, we run the shop API for many merchants as Shopend, and we design a document database for its products, carts, and orders.

After reading this chapter, you should be able to:

  • Define multi-tenancy and explain how it affects a request, authorization, and shopper accounts
  • Explain why merchant-defined attributes do not fit a column for each attribute
  • Define document, collection, and document database, and read a MongoDB lookup
  • Decide what to embed in a document and what to reference
  • Change an embedded item with an update operator and explain why this avoids a lost update
  • Explain why our code must check references and handle documents written under an older design
  • Distinguish a snapshot from a copy that must stay in sync with its source
  • Explain why a list that keeps growing should not be embedded
  • Explain why placing an order needs a conditional update and a transaction across documents
  • Add attributes to a GraphQL schema without breaking existing queries
  • Compare a document design with an attribute table and a JSON column

Sections

  1. Shopend
  2. Multi-tenancy
  3. Product Attributes
  4. Attributes as Columns
  5. A Product as a Document
  6. Designing the Product Document
  7. What Goes in a Document
  8. Connecting Carts to Products
  9. What an Order Must Remember
  10. Lists That Keep Growing
  11. Placing an Order Together
  12. Attributes in the GraphQL Schema
  13. Relational or Document