이벤트 주도 아키텍처

Event-driven architecture

상태가 바뀌었다는 이벤트를 발행하고 소비자가 각자 반응합니다.

···
html
<div class="scene"><div class="title">ORDER PLACED</div><div class="row event"><div class="tile">ORDER</div><div class="stem">→</div><div class="tile pulse">EVENT</div><div class="fork"><div id="billing" class="tile">BILLING</div><div id="notify" class="tile">NOTIFY</div></div></div><div id="eventState" class="muted">Subscribers process independently</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)}}.event .tile{min-width:22%}.stem{color:var(--accent)}.fork{display:grid;gap:10px;flex:1}.fork .tile{text-align:left}.fork .tile:before{content:"↳ ";color:var(--accent)}
js
let phase=0;function tick(){document.getElementById('billing').classList.toggle('on',phase%3!==2);document.getElementById('notify').classList.toggle('on',phase%3===2);document.getElementById('eventState').textContent=phase%3===2?'Notification handled later':'Billing handles its copy';phase++}tick();setInterval(tick,850)

이벤트 주도 구조에서는 생산자가 일어난 사실을 이벤트로 발행하고 구독자가 이를 받아 별도 작업을 합니다. 생산자는 소비자의 실행 시점이나 구현을 직접 알 필요가 없습니다.

데모에서 주문 이벤트 하나가 청구와 알림으로 갈라져 서로 다른 시점에 도착합니다. 메시지 중복과 순서, 실패 시 재처리를 설계해야 합니다.

언제 쓰나

한 변경에 여러 기능이 독립적으로 반응해야 할 때 사용합니다.

페이지로 열기 ↗