Model a one-to-many with one partition
A parent and its children share a partition key, so one Query fetches them together.
Why
A playlist has many tracks. Instead of a join, both live in one item collection: the playlist's META record and its TRACK items all share the partition key PLAYLIST#chill.
So 'the playlist and everything in it' is a single Query. The relationship was resolved at write time, by where you put the items, not at read time by joining them.
Co-locate a parent and its children under one partition key, and the join disappears into a single Query.
Try it. Then change it.
Predict what each request will do. Run it, inspect the response, then change a value in the workbench and try again.
One Query on PLAYLIST#chill returns the playlist record and every track under it.
Built on this
- Verification Service - Is this code still valid?
- SaaS Multi-Tenant - What belongs to this tenant?
- Customer Orders - What did this customer order?
- Job Board - Which jobs are open right now?
- Library Management - Which loans are overdue?
- University Portal - Who is enrolled on this course?
One Query on PLAYLIST#chill returns the playlist record and every track under it.
Choose an access pattern above, or build your own request. See what comes back and what it costs.