App ను గా భావించండి: ప్రతి device ఒక local . Study actions ను ఒక లో మరియు append-only (outbox) లో వ్రాస్తారు; reconnect అయినప్పుడు device తన మరియు చివరి sync నుండి . Conflicts ను ఒక global rule తో , ప్రతి data field యొక్క resolve చేస్తారు.
App ను గా భావించండి: ప్రతి device ఒక local . Study actions ను ఒక లో మరియు append-only (outbox) లో వ్రాస్తారు; reconnect అయినప్పుడు device తన మరియు చివరి sync నుండి . Conflicts ను ఒక global rule తో , ప్రతి data field యొక్క resolve చేస్తారు.
Mental model: దీన్ని git లా భావించండి — ప్రతి device offline లో ఉన్నప్పుడు locally "commit" చేస్తుంది, మరియు sync అనేది overwrite కాదు, ఒక merge.
Device (offline) Server = source of truth
┌──────────────────┐ on reconnect ┌───────────────────────────┐
│ Local DB (SQLite)│ push ops (delta) │ Sync API /sync │
│ + Op log (outbox)│ ─────────────────▶ │ • idempotent by op.id │
│ cursor = lastSeen│ ◀───────────────── │ • merge by semantics │
└──────────────────┘ pull changes>cursor└───────────────────────────┘
Progress DB (Postgres)
Phone clocks unreliable గా ఉంటాయి మరియు రెండు devices ఒకే record ను offline లో edit చేయవచ్చు, కాబట్టి "last write wins" (LWW) నిశ్శబ్దంగా data ను కోల్పోతుంది. Semantics ను బట్టి resolve చేయండి:
// op కి ఒక id ఉంది -> idempotently apply చేయండి (retries double-count చేయవు). clientTs ను నమ్మరు.
function mergeProgress(server, op) {
return {
// progress కేవలం పెరుగుతుంది -> max: late old op దాన్ని ఎప్పటికీ వెనక్కి లాగదు
progress: Math.max(server.progress ?? 0, op.progress),
// studiedMs ఒక additive counter -> delta ను add చేయండి, overwrite చేయకండి
studiedMs: (server.studiedMs ?? 0) + op.studiedMs,
completedAt: server.completedAt ?? (op.progress >= 1 ? op.clientTs : null),
};
}
ఇక్కడ, plain LWW అయితే late గా sync అయ్యే ఒక stale device progress: 0.3 తో server యొక్క 0.9 ను overwrite చేసేది → progress కోల్పోవడం. max తీసుకోవడం మరియు studiedMs ను sum చేయడం sync ను order-independent గా చేస్తుంది — skewed clocks తో millions of devices sync అయినప్పుడు safe.
Client clocks ను నమ్మలేమని మీకు తెలుసా (కాబట్టి pure timestamp LWW కాదు), మీరు sync ను idempotent గా చేస్తారా (op ids), మరియు data meaning ను బట్టి merge చేస్తారా అని interviewer probe చేస్తున్నారు. ఒక weak answer: "timestamps వాడండి, last write wins." ఒక strong answer: replica + op log + idempotency + per-field merge + server as source of truth — మరియు LWW యొక్క data-loss failure ను స్పష్టంగా పేర్కొనడం.
LWW cheap కానీ lossy; semantic merge కి per-field ఆలోచన అవసరం కానీ ఏమీ కోల్పోదు. నిజమైన collaborative editing (notes, documents) అవసరమైనప్పుడు మాత్రమే పూర్తి CRDT/OT వైపు వెళ్ళండి — అది costly, కాబట్టి ప్రతిదానికీ దాన్ని వాడకండి.
జూనియర్ నుండి సీనియర్ వరకు వివరణాత్మక సమాధానాలతో IT ఇంటర్వ్యూ ప్రశ్నల లైబ్రరీ.
విరాళం