CSE Roadmap

Core tier · about 2 hours · 6 parts

Part 6 of 6 · 4 min read

Exercises

Easy

Easy 1: Name the mismatch (15 minutes)

Name the gap between an application's in-memory objects and a relational schema's table-and-foreign-key storage.

Done when: the object-relational mismatch is correctly named.

Hint

The object-relational mismatch.

Easy 2: Identify the relationship that nests naturally (15 minutes)

State which kind of relationship, one-to-many or many-to-many, nests naturally inside a single document.

Done when: one-to-many is correctly identified as the natural fit.

Hint

One-to-many.

Easy 3: Name the two schema approaches (15 minutes)

Name the two approaches to enforcing structure on stored data covered on this page.

Done when: schema-on-read and schema-on-write are both correctly named.

Hint

Schema-on-read and schema-on-write.

Medium

Medium 1: Model an order as a document (25 minutes)

Write a JSON document representing order 9002, for customer 503, containing two line items of your choosing.

Done when: a valid JSON document is produced with an order_id, a customer_id, and an items array containing two line items, each with a book_id, quantity and unit_price.

Hint

A JSON object with order_id 9002, customer_id 503, and an items array of two objects, each with book_id, quantity and unit_price.

Medium 2: Explain why author data resists embedding (25 minutes)

Explain why embedding each author's full biography directly inside every book document they have written is risky.

Done when: the explanation correctly notes that an author who has written several books would have their biography duplicated across every one of those books' documents, risking an inconsistent, only-partially-updated biography if it is ever changed.

Hint

Duplicating a biography across many book documents risks an inconsistent, half-updated biography if it changes later, since every copy would need to be updated separately.

Medium 3: Decide schema-on-read versus schema-on-write for a scenario (30 minutes)

The bookstore wants to store customer reviews, where some reviews include a star rating and a title, and others, imported from an older system, include only free text. Decide which schema approach fits better, and justify it.

Done when: schema-on-read is chosen, justified by the heterogeneous structure of old versus new reviews, which would otherwise require a schema change or null-filled columns to accommodate under schema-on-write.

Hint

Schema-on-read fits better, since old and new reviews have genuinely different shapes, and forcing one fixed shape under schema-on-write would require either a schema change or columns left null for the other review type.

Hard

Hard 1: Trace the rewrite cost of a small update (30 minutes)

A document holding an order with fifty line items has one line item's quantity corrected. Explain what a typical document store actually does to persist that one change, and why.

Done when: the explanation correctly notes the store typically rewrites the entire fifty-line-item document, not just the one changed field, because most document stores do not support modifying part of a stored document in place.

Hint

The store rewrites the entire fifty-line-item document, since most document stores cannot modify part of a stored document in place.

Hard 2: Decide when to split a document (35 minutes)

The bookstore's order documents have grown to include full customer shipping history, author biographies for every book ordered, and a running total of lifetime orders, making individual order documents very large. Propose a fix, grounded in this page's trade-offs.

Done when: a reasonable fix is proposed, such as keeping only the data genuinely needed to render and process one order embedded in the order document itself, and moving independently-changing, shared data, like author biographies or lifetime order totals, out to their own records referenced by ID rather than duplicated inline.

Hint

Keep only what one order actually needs embedded, and move independently-changing shared data like author biographies or lifetime totals out to their own referenced records.

Hard 3: Decide relational versus document for the bookstore's catalog (40 minutes)

The bookstore's catalog associates books with authors, where a book can have multiple authors and an author can have written multiple books. Decide whether to model this part of the bookstore as documents or as relational tables, and justify the choice using this page's material.

Done when: the relational model is chosen for the books-and-authors relationship, justified by it being many-to-many, which a document model cannot embed cleanly without either duplicating author data across every book or performing an application-level lookup in place of a join.

Hint

Relational, since books and authors form a many-to-many relationship that a document model cannot embed without duplicating author data or performing an application-level lookup equivalent to a join.