accesspatterns.dev

Single-table design · Lesson 20 of 20

One table, an application's worth of questions

Generic keys and one overloaded index answer five access patterns with no join and no scan.

Why

This is the whole course in one table. A conference platform has conferences, sessions, speakers and registrations, and five questions to answer. Every item lives in one table, keyed generically, with one overloaded index, GSI1, shared across two entity types.

Run the five examples. A conference and its agenda are one Query; a session and its attendees are another. GSI1 re-keys sessions by speaker and registrations by attendee, so the same index answers both 'every talk this speaker gives' and 'every session this attendee booked'. The fifth is a plain GetItem. Five access patterns, every one a Query or a GetItem, never a join and never a scan.

Model backwards from your access patterns: generic keys and one overloaded index let a single table serve an entire application.

Conference
Try an example

A conference and its sessions share a partition, so one Query returns the lot, sessions in start-time order.

pk(pk)
sk(sk)
name
city
gsi1pk
gsi1sk
title
room
meal

Run an operation to see the raw engine response.

table Conferencekeys pk / skitems 10