Skip to main content

Scenario: Dropbox File Sync Conflicts

Diagram convention: Arrows and messages are labeled 1, 2, 3… to show processing order. Each diagram is followed by a Step-by-step flow table explaining every numbered step.

1. The Interview Question​

"Two users edit the same file offline. Both come online. How do you merge without losing data?"

2. Real-World Context​

DimensionDetail
Company / systemDropbox — block-level sync; exabytes stored; multi-device offline editing
ScaleBillions of files; millions of concurrent sync clients; offline-first mobile and desktop
Why architects careConflict resolution is a product + protocol decision — not just CRDT theory
Public referencesDropbox engineering blog; vector clocks

AWS deployment context​

Typical Dropbox-style sync platform on AWS: desktop/mobile clients with local change queue; ECS Fargate sync API; Amazon S3 for content-addressed block storage; Amazon DynamoDB for file metadata + revision graph; Amazon SQS for async conflict processing; Amazon SNS for conflict notifications; CloudFront for block CDN; AWS KMS for client-side encryption keys.

Step-by-step flow:

StepActionExplanation
1Queue local changeDevice A edits file offline; change queued locally.
2Upload blocksOn reconnect, client uploads only changed 4MB blocks.
3Sync commitSync API receives commit with parent revision ID.
4Device B syncDevice B also uploads with same parent revision — divergent.
5PutObject blocksContent-addressed blocks stored in S3 (dedup).
6Update revisionDynamoDB revision graph updated with vector clock.
7Detect divergenceServer sees two children of same parent → conflict.
8Conflict copyCreate file (conflicted copy).doc — no silent data loss.
9Notify userPush notification to both devices.

3. Step-by-Step Interview Answer​

Minutes 0–8: Requirements​

TypeDetail
Availability offlineLocal edits queue; sync when connected
DurabilityNo silent data loss — both edits preserved
UXUser understands conflicts — "conflicted copy" vs automatic merge
ScopeSingle file conflict (not real-time collab like Google Docs)
BandwidthBlock-level delta sync — only changed 4MB blocks uploaded

Step-by-step flow:

StepActionExplanation
1Offline-firstClient works without network; changes queued.
2No silent lossBoth divergent versions preserved — never overwrite silently.
3Detect concurrencyVector clock / revision graph detects divergent branches.
4User-visibleConflict copy created; user notified to merge manually.

Minutes 8–20: Metadata model and revision graph​

Step-by-step flow:

StepActionExplanation
1–2QueueEach device queues changes with parent revision ID.
3–4SyncOn reconnect, client uploads blocks + metadata commit.
5CompareServer compares revision graph against parent.
6aLinearSingle child of parent — fast-forward, no conflict.
6bDivergentTwo children of same parent — conflict detected.

Revision graph (whiteboard):

Each file version metadata:

FieldPurpose
revision_idUnique server-assigned revision
parent_revision_idPrevious revision — forms DAG
vector_clock{device_A: 3, device_B: 1} — detect concurrency
content_hashSHA-256 of block manifest
block_listOrdered list of content-addressed block hashes
modified_byDevice / user ID
modified_atWall-clock timestamp (advisory only)

On sync:

  1. Client uploads changed blocks (content-addressed — dedup in S3).
  2. Server compares revision graph.
  3. If linear history → fast-forward apply.
  4. If divergent branches → conflict detected → conflict copy.

Step-by-step flow:

StepActionExplanation
1Device A commitUploads changed blocks; claims parent=R1.
2–3Store R2Blocks in S3; revision R2 in DynamoDB.
4ACK R2Device A sync complete.
5Device B commitAlso claims parent=R1 — divergent.
6–7DivergenceR1 already has child R2; R3 is concurrent.
8–9Preserve bothR3 blocks stored; conflict copy metadata created.
10–11NotifyBoth devices informed — no silent overwrite.

Minutes 20–35: Resolution strategies​

StrategyWhenDropbox-style
Last-writer-winsLow stakes metadataRisky for documents — silent data loss
Conflict copiesArbitrary binary filesfile (conflicted copy).doc
Operational transform / CRDTReal-time collabDifferent product (Dropbox Paper)
App-level mergeStructured dataJSON/text merge rules
Three-way mergeText files with baseGit-style — optional for .txt

Principal answer: For arbitrary binary files, automatic merge is impossible — create conflict copy + notify user. For structured types, app-specific merge.

Step-by-step flow:

StepActionExplanation
1Conflict detectedDivergent revision graph.
2BinaryCreate file (conflicted copy).ext — user merges manually.
3Plain textOptional automatic 3-way merge if low risk.
4StructuredApp knows schema — field-level merge.
5Real-timeDifferent architecture — OT/CRDT, not sync conflict.

Minutes 35–45: Interview depth​

TopicDetail
Block-level sync4MB blocks; content-addressed; only changed blocks uploaded
Vector clocksDetect concurrency without central sequencer
BandwidthEdit 1KB in 1GB file → upload 1 block (~4MB max), not 1GB
SecurityClient-side encryption — server sees ciphertext; conflict at metadata layer
Garbage collectionOrphan blocks swept after revision GC

Block-level sync:

Capacity math:

MetricValue
Block size4 MB
Dedup ratio~30% storage saved via content addressing
Metadata ops/sync~10 per file commit
Conflict rate~0.1% of sync commits (multi-device users)

4. Whiteboard Guide​

  1. Draw revision graph: R1 → R2 (device A), R1 → R3 (device B) → CONFLICT
  2. Show block-level sync: file split into hashed blocks; only changed block uploaded
  3. Label conflict copy resolution path
  4. Contrast with Google Docs OT — real-time vs async sync

AWS whiteboard layout​

Step-by-step flow:

StepActionExplanation
1Upload blocksContent-addressed to S3.
2Commit metadataRevision with parent ID to DynamoDB.
3Check parentSingle child = fast-forward.
4DivergentTwo children = conflict.
5Conflict copyBoth versions preserved in S3.
6NotifyUser informed on all devices.

5. Principal-Level Signals​

  • Automatic merge impossible for arbitrary binary — conflict copy is correct
  • Vector clocks detect concurrency — not just timestamps
  • Block-level sync — bandwidth efficiency; conflicts at metadata layer
  • No silent data loss — both versions always preserved
  • Distinguishes sync conflict from real-time collab (OT/CRDT)
  • Client-side encryption — server conflict detection on metadata only

6. Red Flags​

  • Last-writer-wins on documents — silent data loss
  • Full file re-upload on every edit — bandwidth disaster
  • Timestamp-only conflict detection — clock skew causes wrong merges
  • Automatic merge of binary files — corrupts content
  • No user notification on conflict — user discovers days later

7. Follow-Up Questions​

QuestionStrong answer
Dropbox vs Google Docs?Dropbox: async sync + conflict copies; Docs: OT real-time merge
Vector clock vs revision ID?Revision ID for linear; vector clock detects concurrent branches
Delete conflict?Tombstone revision; propagate delete; handle delete vs edit conflict
Shared folder conflict?Same mechanism; notify all folder members
Client-side encryption?Server sees encrypted blocks + metadata; conflict copy still works

9. Practice Drill​

Compare Dropbox conflict model vs Google Docs OT in 10 minutes. Whiteboard revision graph R1→R2, R1→R3 from memory.


10. Production High-Level Design​

10.1 Architecture diagram index​

SectionTopic
§2End-to-end AWS deployment
§3Revision graph + conflict detection
§10.2C4 logical context
§10.3Full stack
§10.4Content-addressed blocks in S3
§11.4Sync commit sequence
§11.5Conflict copy creation
§11.6Local change queue
§12S3 durability + DynamoDB HA
§13Metrics and alerts
§148-week rollout
§15Conflict scenario tests
§16Production readiness

10.2 System context (C4 Level 1)​

10.3 AWS production architecture​

AWS componentSync responsibility
S3Content-addressed blocks; 11 nines durability
DynamoDBRevision graph; file metadata; conditional writes
CloudFrontBlock CDN — reduce upload/download latency
ECS Sync APICommit handler; divergence detection
SQSAsync conflict resolution — don't block sync path
SNSPush conflict notifications to devices

10.4 Block storage model​

Step-by-step flow:

StepActionExplanation
1Split 4MBFile divided into fixed-size blocks.
2SHA-256Each block content-addressed.
3S3 storeDedup — identical blocks stored once.
4ManifestOrdered block list in revision metadata.

11. Production Low-Level Design​

11.1 DynamoDB metadata schema​

Table: FileRevisions

{
"file_id": "f_abc123",
"revision_id": "rev_002",
"parent_revision_id": "rev_001",
"vector_clock": {"device_A": 2, "device_B": 1},
"content_hash": "sha256:manifest_hash",
"block_list": ["abc123", "def456_v2", "ghi789"],
"file_name": "report.docx",
"modified_by": "device_A",
"modified_at": "2026-07-28T22:00:00Z",
"is_conflict_copy": false,
"conflict_of_revision": null
}

GSI: parent_revision_id-index — find all children of a revision (divergence check).

11.2 Sync commit API​

Endpoint: POST /v1/files/{file_id}/commit

{
"parent_revision_id": "rev_001",
"vector_clock": {"device_A": 2},
"block_list": ["abc123", "def456_v2", "ghi789"],
"device_id": "device_A",
"client_commit_id": "cc_8f3a"
}

Response (success):

{
"revision_id": "rev_002",
"status": "applied"
}

Response (conflict):

{
"revision_id": "rev_003",
"status": "conflict",
"conflict_copy_path": "/report (conflicted copy).docx",
"conflicting_revision": "rev_002"
}

11.3 Sync commit handler — step-by-step​

Handler pseudocode:

def commit_revision(file_id: str, commit: CommitRequest) -> CommitResponse:
# Step 1: Idempotency
if existing := ddb.get_client_commit(commit.client_commit_id):
return existing

# Step 2: Check for divergence
siblings = ddb.query_children(commit.parent_revision_id)
if siblings:
# DIVERGENCE — concurrent edit detected
conflict_rev = create_conflict_copy(file_id, commit, siblings[0])
notify_devices(file_id, conflict_rev)
return CommitResponse(status="conflict", revision_id=conflict_rev.id)

# Step 3: Linear fast-forward
new_rev = ddb.put_revision(
file_id=file_id,
parent=commit.parent_revision_id,
vector_clock=merge_vector_clock(commit),
block_list=commit.block_list,
condition=ParentHasNoChildren(commit.parent_revision_id),
)
return CommitResponse(status="applied", revision_id=new_rev.id)

11.4 Conflict resolution handler​

Conflict copy naming:

Original: /Projects/report.docx
Conflict: /Projects/report (conflicted copy 2026-07-28).docx

Step-by-step flow:

StepActionExplanation
1Load bothFetch R2 (device A) and R3 (device B) metadata.
2Copy blocksR3 blocks copied to new S3 path — preserved.
3Create metadataNew file entry with is_conflict_copy=true.
4NotifySNS push to all folder members.
5User mergesManual merge in app — product decision.

11.5 Offline client queue​

Local queue schema (SQLite):

CREATE TABLE pending_changes (
id INTEGER PRIMARY KEY,
file_path TEXT NOT NULL,
parent_revision TEXT NOT NULL,
block_hashes TEXT NOT NULL, -- JSON array
vector_clock TEXT NOT NULL, -- JSON
created_at INTEGER NOT NULL,
retry_count INTEGER DEFAULT 0
);

Step-by-step flow:

StepActionExplanation
1Save localEdit saved to local filesystem immediately.
2Queue changeMetadata queued in SQLite — survives app restart.
3On reconnectUpload blocks then commit in order.
4Apply server stateHandle conflict or fast-forward response.

11.6 Vector clock merge rules​

def is_concurrent(clock_a: dict, clock_b: dict) -> bool:
"""True if neither clock dominates the other."""
a_dominates = all(clock_a.get(k, 0) >= clock_b.get(k, 0) for k in set(clock_a) | set(clock_b))
b_dominates = all(clock_b.get(k, 0) >= clock_a.get(k, 0) for k in set(clock_a) | set(clock_b))
return not a_dominates and not b_dominates

def merge_vector_clock(local: dict, server: dict) -> dict:
keys = set(local) | set(server)
return {k: max(local.get(k, 0), server.get(k, 0)) + (1 if k in local else 0) for k in keys}
ScenarioVector clocksResult
A then B (sequential)A: {A:2}, B: {A:2,B:1}B dominates A — fast-forward
A and B concurrentA: {A:2}, B: {B:2}Concurrent — conflict
Same device retrySame clockIdempotent — dedup by client_commit_id

12. HA/DR and Durability​

ComponentDurabilityHA
S3 blocks11 nines; cross-AZ replication99.99% availability
DynamoDB metadataMulti-AZ; point-in-time recovery99.99%
Revision graphNo single point of loss — both branches preserved
Client local queueDevice-local SQLite — user responsible for backup

13. Observability and Operations​

MetricAlert threshold
sync.conflict_rate> 1% of commits — UX issue
sync.commit_latency_p99> 2s
block.upload_failure_rate> 0.1%
offline_queue_depth per device> 1000 changes — stuck sync
orphan_block_countGrowing — GC job failure

Structured log:

{
"file_id": "f_abc123",
"event": "conflict_detected",
"parent_revision": "rev_001",
"sibling_revision": "rev_002",
"new_revision": "rev_003",
"devices": ["device_A", "device_B"],
"resolution": "conflict_copy"
}

14. Implementation Roadmap (8-Week Rollout)​

WeekDeliverable
1S3 block storage + content addressing
2DynamoDB revision graph schema
3Sync commit API + fast-forward path
4Divergence detection + vector clocks
5Conflict copy creation + SNS notifications
6Offline client queue (SQLite)
7Block-level delta sync in desktop client
8Conflict rate dashboards + GC job

15. Testing Strategy​

TestPass criteria
Sequential edits A then BFast-forward; no conflict
Concurrent offline editsConflict copy created; both preserved
Same client_commit_id retryIdempotent — same revision returned
Edit 1KB in 1GB fileOnly 1 block uploaded
Delete vs edit conflictTombstone wins or conflict copy — policy defined
Device loss before syncLocal queue lost — document limitation

16. Architecture Review Checklist​

#GateStatus
1Block-level sync — not full file re-upload☐
2Revision graph with parent_revision_id☐
3Vector clock concurrency detection☐
4Conflict copy — no silent data loss☐
5SNS notification on conflict☐
6Offline SQLite change queue☐
7client_commit_id idempotency☐
8S3 block GC for orphan blocks☐
9Conflict rate dashboard☐
10Distinguish sync conflict from real-time collab scope☐