SQLite-backed edge actors

SQLite 기반 엣지 액터

An actor per identifier keeps its own SQLite-backed state.

···
html
<div class="scene"><div class="title">ACTOR STATE SURVIVES RESTART</div><div class="row actors"><div class="tile" id="actorA">ACTOR A<div id="countA">0</div></div><div class="tile" id="actorB">ACTOR B<div id="countB">0</div></div></div><div class="storage">SQLite A <span id="storeA">0</span> · SQLite B <span id="storeB">0</span></div><div class="muted" id="actorState">Requests update isolated state</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)}}.actors .tile{flex:1}.actors .tile div{font:700 1.8em ui-monospace,monospace;color:var(--accent);margin-top:6px}.storage{border:1px solid var(--line);border-radius:6px;background:var(--bg);padding:7px;text-align:center}
js
let a=0,b=0,phase=0;function tick(){const p=phase%4;if(p===0||p===1)a++;if(p===2)b++;document.getElementById('actorA').classList.toggle('on',p!==2);document.getElementById('actorB').classList.toggle('on',p===2);document.getElementById('countA').textContent=a;document.getElementById('countB').textContent=b;document.getElementById('storeA').textContent=a;document.getElementById('storeB').textContent=b;document.getElementById('actorState').textContent=p===3?'A restarted; SQLite restores '+a:'Actor '+(p===2?'B':'A')+' handles request';phase++}tick();setInterval(tick,900)

A SQLite-backed Durable Object binds execution and storage to an instance addressed by an identifier. Requests to that object read or change its state, which survives instance restarts.

The demo increments A and B separately and restores A after restart. Cross-object queries and global joins may need another data design.

When to use

Consider it for state naturally grouped by a user, room, or session key.

Open as page ↗