# Outbox And Inbox Patterns

> Reliably publish and consume events/messages using the transactional outbox and inbox patterns. Use when you need consistent state changes + message publishing without distributed transactions.

- Skill: `itsual/outbox-and-inbox-patterns` (Agent Skill)
- Install (CLI): `npx skillmds@latest add itsual/outbox-and-inbox-patterns`
- Raw SKILL.md: https://api.skillmd.com/api/skills/itsual/outbox-and-inbox-patterns/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Coding & Dev Tools
- Author: itsual (https://skillmd.com/u/itsual)
- Updated: 2026-09-21
- Page: https://skillmd.com/skills/itsual/outbox-and-inbox-patterns

---


# Outbox and Inbox Patterns

## Overview

The outbox pattern ensures that a database change and the corresponding message publication happen atomically. The inbox pattern helps consumers process messages exactly-once (or idempotently).

## When to Use

- Publishing domain events after a state change
- Avoiding dual-write problems between DB and message broker
- Building reliable event-driven flows

## Core Ideas

- **Outbox**: Write the business data and an “outbox” record in the same transaction; a relay publishes from the outbox
- **Inbox**: Record processed message IDs so duplicates can be ignored
- Combined with idempotent handlers for strong reliability

## Principles

- Dual writes without a transaction are a common source of bugs
- Make the relay process observable and restartable
- Clean up old outbox/inbox records with a retention policy

## Verification

- A state change is never committed without the corresponding outbox entry (and vice versa)
- Consumers can survive duplicate deliveries

