Product design

Letterboxd: one film, two viewings, two experiences

Letterboxd is a place for film lovers to log, rate and discuss movies. It separates having seen a film from watching it on a particular day, preserving the dates and impressions of each rewatch.

Break down the problem and try your own design and implementation first. Then explore the reasoning to check states, edge cases, trade-offs, and ways to test your approach. The guide offers a reasoning path, not a complete implementation.

01
CODE EXERCISE

Update a rating by viewing-entry ID

Implement a rating-update function for a film diary. A film can have several viewing entries. Editing one old entry must preserve the other entries while updating that film's current rating to match this edit.

  1. Given data: state contains entries and currentRatings. Initially, entries is [{id:"A1",filmId:"A",date:"03-02",stars:3},{id:"A2",filmId:"A",date:"10-20",stars:4},{id:"B1",filmId:"B",date:"10-21",stars:5}], and currentRatings is {A:4,B:5}. id identifies a viewing, filmId identifies a film, date is for display, and stars is its rating.
  2. Behavior: Implement updateRating(state, entryId, stars), returning a complete new state without changing the input state. entryId is guaranteed to exist and be unique; stars is an integer from 1 to 5. Change only the selected entry's rating and that film's currentRatings value. Preserve entry order, dates and all other fields. The current rating follows this edit, rather than selecting by viewing date.
  3. Acceptance: Starting with the initial data, change A1 to 2. The result has A1:2, A2:4, B1:5 and currentRatings {A:2,B:5}; the original input is unchanged. Pass the result into a second call changing A2 to 5: expect A1:2, A2:5, B1:5 and {A:5,B:5}. Setting A2 to 5 again leaves the content unchanged.
  4. Deliver: Implement the function in a familiar language, run this sequence and briefly explain why the update operation needs entryId instead of only filmId. Local data is enough; no page or database is required.
Explore the reasoning
  1. Distinguish the film's identity from the viewing's identity: one filmId can have several entryIds.
  2. Put the entry update and the current-rating update in one operation so callers cannot perform only half of the change. Consider how to copy the changed data without altering the old input.
  3. Trace A1, A2 and film A's current rating through both edits. In particular, editing an earlier viewing still updates the current rating according to the stated rule.