The first thing that comes to mind ist LISTEN/NOTIFY from postgres.
You can listen per code and notify per code.
https://www.postgresql.org/docs/current/sql-listen.html
The js adapter for pg can handle this: https://medium.com/@simon.white/postgres-publish-subscribe-w...