CRDT merge

CRDT 자동 병합

Concurrent changes converge even when replicas receive them in different orders.

···
html
<div class="scene"><div class="title">CONCURRENT SET MERGE</div><div class="row crdt"><div class="tile">REPLICA A<div id="setA" class="set">{A}</div></div><div class="merge">⇄<small>op exchange</small></div><div class="tile">REPLICA B<div id="setB" class="set">{B}</div></div></div><div id="mergeState" class="muted">Independent adds while offline</div></div>
css
.scene{width:min(94vw,760px);height:min(86vh,320px);padding:clamp(10px,2.5vmin,18px);border:1px solid var(--line);border-radius:14px;background:var(--surface);color:var(--fg);font:500 clamp(11px,1.3vw,16px)/1.25 "Pretendard Variable",Pretendard,-apple-system,sans-serif;display:flex;flex-direction:column;gap:clamp(7px,1.6vmin,12px);overflow:hidden}.scene *{box-sizing:border-box}.title{font-weight:750;color:var(--accent)}.muted{color:var(--muted)}.mono{font-family:ui-monospace,monospace}.row{display:flex;align-items:center;justify-content:center;gap:clamp(5px,1.4vmin,12px);flex:1;min-height:0}.tile{border:1px solid var(--line);border-radius:8px;background:var(--bg);padding:clamp(6px,1.6vmin,12px);text-align:center;min-width:0}.on{border-color:var(--accent)!important;background:color-mix(in srgb,var(--accent) 12%,var(--surface))!important}.pulse{animation:pulse 1.6s infinite alternate}@keyframes pulse{to{border-color:var(--accent);transform:translateY(-3px)}}.crdt .tile{flex:1}.set{font:700 1.5em ui-monospace,monospace;color:var(--accent);margin-top:9px}.merge{color:var(--accent);font-size:1.7em;text-align:center}.merge small{display:block;font:500 clamp(11px,1.2vw,14px) "Pretendard Variable",Pretendard,-apple-system,sans-serif;color:var(--muted)}
js
let phase=0;function tick(){const p=phase%3;document.getElementById('setA').textContent=p===2?'{A,B}':'{A}';document.getElementById('setB').textContent=p===2?'{A,B}':'{B}';document.getElementById('mergeState').textContent=['A adds A; B adds B','Operations travel in different order','Both replicas converge to {A,B}'][p];phase++}tick();setInterval(tick,1050)

A CRDT embeds merge rules in a data type so replicas can exchange operations. Supported operations converge even if received in different orders.

The demo has A and B add distinct items and receive changes in opposite orders, yet reach the same set. Business-level conflicts still require product rules.

When to use

Use it to merge concurrent offline edits across devices without central locking.

Open as page ↗