๐ก Real-World Patterns: Notifications & Dashboards
Discover production patterns for event-driven dApps
Listen for smart contract events in real-time
Your Progress
0 / 5 completed๐จ Production Patterns
Theory meets practice. Every major dApp uses event subscriptions, but each solves different problems. Wallet trackers monitor user activity, price feeds aggregate DEX swaps, NFT platforms track collection transfers, DAOs send governance alerts. The pattern is the sameโsubscribe, filter, handle eventsโbut the filters and logic differ. Let's explore 4 production-ready patterns used by top protocols.
๐ฎ Interactive: Pattern Explorer
Select a real-world use case to see its event subscriptions, filters, and implementation details. Study these patterns to understand how production dApps work.
๐ Wallet Activity Tracker
Monitor all incoming/outgoing transactions for a specific wallet. Used by portfolio apps, tax software, and wallet notifications.
{
address: null, // All contracts
topics: [
null, // Any event
"0x000...userAddress", // User is sender (indexed param 1)
"0x000...userAddress" // OR user is receiver (indexed param 2)
]
}Portfolio trackers (Zapper, DeBank), wallet apps (MetaMask, Rainbow), tax tools (CoinTracker)
When Alice receives USDC, her wallet instantly shows notification: "Received 1000 USDC from Bob"
๐๏ธ Architecture Best Practices
Don't process events synchronously in WebSocket handler. Push to queue (Redis, RabbitMQ), process in background workers. Prevents blocking, enables retry logic, scales horizontally.
Events can be delivered multiple times (reconnections, node issues). Use transaction IDs as unique keys. Check if event already processed before applying changes. IF NOT EXISTS INSERT in SQL.
WebSocket dies? Reconnect with increasing delays: 1s, 2s, 4s, 8s, max 30s. Prevents hammering node during outages. Reset delay after successful reconnection.
Primary fails? Switch to backup provider (Infura โ Alchemy โ QuickNode). Maintain subscription state, resubscribe on failover. Zero downtime for users.
โก Performance Optimization
- โBatch DB writes: Collect 100 events, write once instead of 100 individual writes. Reduces DB load by 100x.
- โCache frequently accessed data: Current price, token metadata, user balances. Redis in front of DB for sub-millisecond reads.
- โUse indexed DB fields: Index transaction hash, block number, user address. Query performance critical when handling millions of events.
- โMonitor subscription health: Track events/sec, latency, reconnections. Alert if rate drops (indicates filter issue or node problem).
๐ก Key Insight
Production event handling is about resilience. WebSocket connections fail. Nodes restart. Networks partition. Your app must handle all of this gracefully. The pattern: filter aggressively (reduce noise) โ queue events (decouple processing) โ process idempotently (handle duplicates) โ reconnect intelligently (exponential backoff). This architecture scales from 10 events/min to 10,000 events/min without code changes. Study how OpenSea, Uniswap, and Etherscan handle eventsโthey all follow these patterns. Your dApp should too. Event subscriptions aren't just about real-time updatesโthey're about building reliable, scalable infrastructure.