International Edition
Latest News
Technology

iCloud Photo Metadata Sync Uses Vector Clocks and Shared Logical Clock for Offline Conflict Resolution

Apple’s iCloud photo sync uses a shared logical clock and per-field vector clocks to resolve offline metadata conflicts, a design that appears in the company’s engineering interview loop, PracHub reported. Each addPhoto or editPhoto call increments a global…

iCloud Photo Metadata Sync Uses Vector Clocks and Shared Logical Clock for Offline Conflict Resolution

Apple’s iCloud photo sync uses a shared logical clock and per-field vector clocks to resolve offline metadata conflicts, a design that appears in the company’s engineering interview loop, PracHub reported.

  • Each addPhoto or editPhoto call increments a global logical timestamp starting at zero.
  • Vector clocks track edits per device and field; concurrent edits fall back to last-writer-wins with device ID as tiebreaker.
  • Sync merges clocks element-wise and writes the winning value to both devices.
  • The problem is listed under Apple’s Class Design and Low Level Design interview rounds on 2daysbeforeinterview.com.

The system maintains a single logical clock across all devices. It starts at zero and increments by one for every addPhoto or editPhoto call, PracHub reported. That timestamp becomes the write’s logical time t and is stored in the vector clock entry for the editing device.

Every metadata field — title, tags, favorite — carries its own vector clock. addPhoto on device d initializes each field’s clock to {d: t}. An editPhoto on device d updates only that field’s clock entry for d to the new timestamp t, leaving other device entries unchanged, according to the PracHub specification.

Company interview questions
Photo: 2daysbeforeinterview.com

Clock X dominates clock Y when every entry in X is greater than or equal to the matching entry in Y and at least one is strictly greater; missing devices count as zero. During a bidirectional sync, each shared photo is resolved field by field.

If one clock dominates, its value wins. If the clocks are concurrent — neither dominates — the write with the later timestamp wins; a lexicographically smaller device ID breaks remaining ties. Both devices receive the winning value, its timestamp, and the element-wise maximum of the two clocks, PracHub reported.

In a two-device scenario, an iPhone adds a photo at t=1, then syncs to a Mac. Offline, the iPhone changes the title at t=2 and the Mac changes it at t=3. The resulting title clocks are {iphone: 2} and {iphone: 1, mac: 3} — each ahead on one device, so the edits are concurrent. The later write (t=3, from the Mac) wins, and both devices end with the merged clock {iphone: 2, mac: 3}, PracHub reported.

The same design problem appears in Apple’s Class Design and Low Level Design rounds, according to 2daysbeforeinterview.com. The site categorizes it under “Software Engineering Fundamentals” and notes constraints of up to ten devices, 20-character photo IDs, and 10,000 total operations.

About the author: Technology Desk

Technology Desk at Archynewsy.