Part 5 of 5 · 4 min read
Exercises
Easy
Easy 1: Name the deciding factor (15 minutes)
Name the factor that should decide which data model fits a given piece of data.
Done when: the access pattern, how the data is actually read and written, is correctly named.
Hint
The access pattern, how the data is actually read and written.
Easy 2: Name the term for using several models at once (15 minutes)
Name the term for using more than one kind of data store within a single system.
Done when: polyglot persistence is correctly named.
Hint
Polyglot persistence.
Easy 3: Name the cost polyglot persistence adds (15 minutes)
Name one real cost that comes with running several different data stores in one system.
Done when: operational cost, or the cross-store consistency problem, is correctly named as a real cost.
Hint
Operational cost (running more systems) or the cross-store consistency problem.
Medium
Medium 1: Match a described workload to a model (25 minutes)
A workload always looks up a session by one exact token, never by anything inside the session. Decide which model fits, and justify it.
Done when: key-value is chosen, justified by the lookup always being by one exact key, with no need to query by the session's contents.
Hint
Key-value, since the lookup is always by one exact key with no need to query by contents.
Medium 2: Match a different described workload to a model (25 minutes)
A workload needs to find chains of relationships several steps deep, such as friends of friends who share an interest. Decide which model fits, and justify it.
Done when: graph is chosen, justified by the multi-step, chained relationship pattern, which a graph traverses directly and a relational schema would need many successive joins to express.
Hint
Graph, since it traverses multi-step, chained relationships directly, where a relational schema would need many successive joins.
Medium 3: Identify a cross-store consistency risk (30 minutes)
The bookstore caches a customer's loyalty tier, Gold or Silver, in a key-value store, while the authoritative tier is stored in the relational customer table. Identify the risk this creates, and propose a mitigation.
Done when: the risk correctly identifies that the cached tier can go stale if the authoritative tier changes without the cache being updated, and a reasonable mitigation is proposed, such as updating or expiring the cached copy whenever the authoritative tier changes.
Hint
The cached loyalty tier can go stale if the authoritative tier changes without updating the cache; mitigate by updating or expiring the cached copy whenever the authoritative value changes.
Hard
Hard 1: Design a polyglot split for a new feature (30 minutes)
The bookstore adds a feature letting customers tag books with free-form keywords, searched later by tag. Decide which model from this level fits storing and querying these tags, and justify it.
Done when: a reasonable model is proposed and justified using this page's framework, such as a document model if tags are usually read together with the book they annotate, or a dedicated search-oriented structure if free-text tag search across the whole catalog is the primary access pattern; either choice is acceptable if justified by the stated access pattern.
Hint
A document model fits if tags are read together with their book; a dedicated search structure fits if free-text search across the whole catalog is the main access pattern; either is acceptable if justified by the access pattern.
Hard 2: Argue against polyglot persistence for a small team (35 minutes)
A two-person team is launching a small version of the bookstore and is deciding whether to use five different data stores, one per model covered in this level, or just one relational database for everything. Argue for the single-database choice.
Done when: the argument correctly notes that operating five different kinds of data store is a real ongoing cost a two-person team likely cannot sustain, and that accepting a less-than-ideal fit for some data in a single relational database is a reasonable trade against that operational burden.
Hint
Operating five different stores is a real ongoing cost a two-person team likely cannot sustain; accepting a less-than-ideal fit in one relational database is a reasonable trade against that burden.
Hard 3: Audit the bookstore's own polyglot design (40 minutes)
Using the bookstore's described split, catalog and orders relational, carts key-value, recommendations graph, event log column-family, identify which single piece of this design is most at risk of a cross-store consistency problem, and explain why.
Done when: a reasonable piece is identified, such as a customer's identity or loyalty status needing to stay consistent between the relational customer table and any cached or duplicated copy held in the key-value cart store or the graph's customer vertices, with a correct explanation that no single store here enforces that consistency automatically.
Hint
A customer's identity or loyalty status needing to stay consistent between the relational table and any cached or duplicated copy elsewhere is at risk, since no single store here enforces that consistency automatically.