Event Sourcing Explained
Event Sourcing Explained
Why Synap never forgets: Time-travel, audit trails, and infinite undo
Instead of updating data and losing history, Synap records every change as an immutable event. This enables capabilities impossible in traditional systems.
The Traditional Approach (and Its Problems)
How Most Apps Work:
What's Lost:
- Complete history
- Change attribution
- Reasoning/context
- Ability to undo
- Audit trail
- Debugging capability
Event Sourcing: A Better Way
How Synap Works:
What's Preserved:
- ✅ Complete history
- ✅ Who made each change
- ✅ Exact timestamps
- ✅ Can undo to any point
- ✅ Full audit trail
- ✅ Can replay/debug
5 Superpowers Events Enable
1. Time-Travel
Go back to any point in time:
UI You Can Build:
2. Infinite Undo
Undo anything, anytime:
UI You Can Build:
3. Full Audit Trail
Know exactly what happened:
UI You Can Build:
4. AI Transparency
Understand why AI did something:
UI You Can Build:
5. Disaster Recovery
Rebuild everything from events:
Why This Matters:
- Events = source of truth
- Projections = disposable views
- Can always rebuild
- No data loss even if DB corrupted
How It Works: Events → State
1. Event Structure
2. Event Types
3. Event Application
Events + Projections
Two-part system:
Example:
Query Flow:
Comparison with Traditional
| Aspect | Traditional DB | Event Sourcing |
|---|---|---|
| Write | UPDATE table | APPEND event |
| History | ❌ Lost | ✅ Complete |
| Undo | ❌ Impossible | ✅ Easy |
| Audit | ⚠️ Manual logs | ✅ Automatic |
| Recovery | ⚠️ Backups only | ✅ Replay events |
| Debugging | ❌ Hard | ✅ Full trace |
| AI transparency | ❌ Hidden | ✅ Full reasoning |
| Complexity | Low | Medium |
Real-World Examples
Example 1: Collaborative Note
Example 2: AI Suggestion Audit
Best Practices
1. Events are Immutable
2. Projections are Disposable
3. Rich Event Metadata
4. Meaningful Event Types
Synap's Production Implementation
How Synap implements event sourcing in production
3-Phase Event Pattern
Synap uses a 3-phase event flow for security and transparency:
Why 3 Phases?
- Security: Centralized permission checks
- AI Transparency: AI proposals require user approval
- Audit Trail: Complete record of who requested, who approved, when executed
Real Example
Query the history:
Dual-Write Pattern
Every event written to BOTH TimescaleDB and Inngest:
Benefits:
- ✅ TimescaleDB: Permanent, queryable, compressed
- ✅ Inngest: Instant workers, retries, observability
- ✅ Fault tolerant: Event always saved even if worker fails
Worker-Based Permissions
Permissions validated in workers, not API layer:
Why workers?
- ✅ Centralized permission logic
- ✅ Every decision is an audited event
- ✅ Easy to extend (roles, sharing, etc.)
- ✅ AI approval workflow built-in
Performance Considerations
Snapshots for Speed
Problem: Replaying 1 million events is slow.
Solution: Periodic snapshots.
Next Steps
- Tutorial: Build Activity Timeline - Event-based UI
- Guide: Event-Driven Workflows - Advanced patterns
- API Reference: Events API - Complete event API
- What is Synap? - How events enable superpowers
Resources
- Theory: Martin Fowler - Event Sourcing
- Implementation: Event Store Documentation
- CQRS: Command Query Responsibility Segregation pattern
:::info Learn more on the website
- User-friendly guide to the Event Chain — practical overview of event sourcing in Synap :::
