Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Eventual Consistency

MediumSQL · PostgreSQL00:00
Practice interviewer
In session
5 left
00:00

Your question is Eventual Consistency. Start with the requirements and the two tables on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

Spotify's catalog pipeline writes updates to a source-of-truth table first, then propagates them to the serving layer with a delay. Write a SQL query to find catalog items where the serving layer is still stale.

Requirements

  1. Return items whose source version is newer than the serving version, or that do not exist in the serving layer yet.
  2. Show the item id, item type, source version, serving version, and a status label of pending_sync or missing_in_serving.
  3. Order the result by item_id.

Schema

catalog_source
ColumnTypeDescription
item_idPKINTSource system item id
item_typeVARCHAR(20)Item type, such as track or playlist
source_versionINTLatest version in the source system
updated_atTIMESTAMPLast source update time
catalog_serving
ColumnTypeDescription
item_idPKINTServing layer item id
item_typeVARCHAR(20)Item type in serving
serving_versionINTVersion currently visible in serving
last_synced_atTIMESTAMPLast sync time into serving
Tablescatalog_sourcecatalog_serving
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results