Postgres as Your Platform: Building Event-Driven Systems with Schema Changes
Postgres event triggers, transactional DDL and LISTEN/NOTIFY can turn schema changes into reliable events that drive downstream automation such as SDK generation, warehouse syncs and documentation updates, with no external queue. The pattern uses a ddl_command_end event trigger that writes pg_event_trigger_ddl_commands() metadata to an outbox table and calls pg_notify, all inside the DDL transaction, so events exist exactly when the schema change commits. A Python psycopg2 worker listens for notifications and claims rows from the outbox, which also supports polling fallback, replay and monitoring of backlog. Practical details cover tagging tenant schemas, using a session setting to avoid infinite loops when automation itself runs DDL, connecting directly rather than through a pooler, and keeping Neon listeners from scaling to zero.
Related posts
- Postgres Event Triggers Are Now Supported in Neon
Neon mediumAdept
Neon now supports Postgres event triggers through the neon_superuser role, and they behave exactly as in vanilla Postgres. Unlike row-level triggers, event triggers fire on DDL commands such as CREATE, ALTER and DROP. They can audit schema changes on ddl_command_end, automate metadata updates or alerts, and feed schema changes to sync engines like Zero via pg_event_trigger_ddl_commands(). Short examples show blocking DROP TABLE for non-admin roles and cleaning up orphaned pg_cron jobs on sql_drop using pg_event_trigger_dropped_objects().
- Change Data Capture with Serverless Postgres
Neon mediumAdept
Neon has released Postgres logical replication in beta, letting Neon databases act as publishers that stream an initial snapshot plus row-level changes to external stores for change data capture and real-time analytics. Under the hood, the walsender decodes the WAL through an output plugin: pgoutput for Postgres-to-Postgres replication, and newly supported wal2json for systems such as Kafka or Materialize. Enabling it is irreversible and restarts the compute. Neon can't act as a subscriber yet, active subscribers can prevent scale-to-zero, DDL changes are not replicated, and replication lag should be monitored.
- Event-driven architectures using Neon and Sequin
Neon mediumAdept
Sequin offers a lighter alternative to Debezium plus Kafka for change data capture on Neon Postgres, using a logical replication slot to build a strictly ordered "Sequence" of table rows that consumers can read, rewind and replay without copying data into a separate system. Setup covers enabling logical replication in Neon, creating a pgoutput replication slot and a publication, defining a Sequence with a sort column, and creating a pull consumer group with optional SQL filters and a chosen start position. Consumers fetch batches over an HTTP receive endpoint and acknowledge them with ack tokens, and Sequin redelivers rows until they are acknowledged.
- The Hidden Ops Layer of Agent Platforms
Neon mediumAdept
Anything's Max coding agent gets a dedicated Neon database branch for every session, created in about 200 ms. The agent runs its migrations there and merges back into development atomically through Neon's restore API. Failed migrations go to a separate LLM "Migration Fixer" for up to three retries before rollback, and merges fail if the development schema changed in the meantime. After crashed sessions left 2,847 orphaned branches, the team added a 6-hourly cleanup job plus 24-hour expires_at timestamps on branches. Connection pooling and 0.25–1 CU autoscaling handle bursty workloads of about 30 peak connections.
- Stream data from Neon to external data sources via logical replication
Neon mediumAdept
Neon now supports outbound Postgres logical replication in beta, letting a Neon database publish WAL-decoded inserts, updates and deletes to warehouses, Kafka, CDC tools and other Postgres databases; inbound replication is coming later. Logical replication covers data changes only, not DDL, so schema changes must be applied to subscribers by hand. It uses publications, decoder plugins like pgoutput, and replication slots that retain WAL until subscribers consume it. In Neon, enabling it restarts all computes, only roles created via Console/CLI/API carry the REPLICATION privilege, and inactive slots are dropped after 75 minutes when other active slots exist. Setup guides cover Airbyte, Fivetran, Confluent, Materialize, Decodable, Bemi, DoubleCloud and Sequin.