๐—ง๐—ต๐—ฒ ๐—ฃ๐—ผ๐˜„๐—ฒ๐—ฟ ๐—ผ๐—ณ ๐—ฃ๐—ผ๐˜€๐˜๐—ด๐—ฟ๐—ฒ๐—ฆ ๐—Ÿ๐—œ๐—ฆ๐—ง๐—˜๐—ก/๐—ก๐—ข๐—ง๐—œ๐—™๐—ฌ You need to keep your video metadata up to date. But caching can make this hard.

Here's how we solved this problem:

We use a trigger to send notifications when metadata changes. This trigger runs inside the same transaction as the write. So if the transaction rolls back, the notification is discarded.

The listener is a separate daemon. It holds a Postgres connection open and blocks on incoming notifications. When it gets a notification, it updates the cache.

We also have a reconciliation sweep to catch any missed notifications. This sweep runs periodically and updates the cache for any changed metadata.

Some key lessons we learned:

Source: https://dev.to/ahmet_gedik778845/real-time-video-metadata-invalidation-with-postgres-listen-and-notify-2fnl