Skip to main content

Notification Producer

The Notification Producer is a background service that monitors blockchain events and generates push notifications for users subscribed to CoW Protocol updates. It tracks trades, expired orders, and CMS notifications across multiple chains.

Purpose and Responsibilities

The Notification Producer performs the following tasks:
  • Trade Notifications: Monitors executed trades and generates notifications for users
  • Expired Order Notifications: Detects expired orders and notifies affected users
  • CMS Notifications: Fetches and distributes content management system notifications
  • Multi-Chain Indexing: Tracks events across all supported CoW Protocol chains
  • State Persistence: Maintains indexer state to resume from the last processed block after restarts

How to Run

Development

The producer will start monitoring all supported chains by default.

Run for Specific Chains

You can limit the producer to specific chains using the NOTIFICATIONS_PRODUCER_CHAINS environment variable:

Production

Docker

Key Configuration Options

Chain Selection

Example: NOTIFICATIONS_PRODUCER_CHAINS=1,100,137

RPC Configuration

The producer requires RPC endpoints for each chain being monitored:

Database Configuration

RabbitMQ Configuration

Optional: Redis Cache

Producer Components

The service runs three types of notification producers concurrently:

1. Trade Notification Producer

Purpose: Generates notifications when users’ orders are executed. How it works:
  • Polls blockchain for new blocks
  • Queries CoW Protocol settlement events
  • Matches trades to subscribed user accounts
  • Enriches notifications with token information and USD values
  • Sends notifications to RabbitMQ queue
Key Features:
  • Batch processing (up to 5000 blocks per batch)
  • State persistence for crash recovery
  • Handles blockchain reorgs gracefully

2. Expired Orders Notification Producer

Purpose: Notifies users when their orders expire without being filled. How it works:
  • Monitors orders approaching expiration
  • Checks if orders were filled or cancelled
  • Generates notifications for truly expired orders
  • Sends to notification queue

3. CMS Notification Producer

Purpose: Fetches and distributes notifications from the content management system. How it works:
  • Polls CMS for new announcements
  • Distributes to all subscribed users
  • Handles general protocol updates and announcements

Main Functionality

Block Indexing

The trade notification producer implements a robust block indexing mechanism:

Notification Queue

Notifications are sent to RabbitMQ for consumption by delivery services (e.g., Telegram bot):

Dependencies

Required Services

  • PostgreSQL Database - Stores indexer state and subscription information. Required tables: indexer_state, push_subscriptions, on_chain_placed_orders, expired_orders
  • RabbitMQ - Message queue for distributing notifications to consumers. Queue: notifications
  • Blockchain RPC Nodes - HTTP or WebSocket endpoints for each monitored chain

Optional Services

  • Redis - Caching layer for token metadata and frequently accessed data. Improves performance by reducing redundant API calls and blockchain queries.

Database Schema

The indexer state table stores progress for each producer:
State Structure:

Graceful Shutdown

The producer implements graceful shutdown with a 30-second timeout:
This ensures:
  • In-progress block processing completes
  • Database state is saved
  • No notifications are lost
  • Clean disconnection from RabbitMQ and database

Testing Notifications

Quick test to send a notification to your subscribed account:
This will:
  1. Create a test notification
  2. Send it to the RabbitMQ queue
  3. Be delivered by connected consumers (e.g., Telegram bot)

Nx Commands

Monitoring and Logs

The producer outputs structured logs with prefixes:
Log Levels:
  • trace - No new blocks to index
  • debug - Block processing details
  • info - Notifications sent, producer lifecycle
  • warn - RPC lag, temporary issues
  • error - Critical errors, retries
Last modified on March 11, 2026