Skip to content

Watcher

Port: :4040
Source: apps/workers/watcher/

The watcher keeps the Redis cache in sync with MongoDB. It consumes change stream events from Kafka and writes or removes the relevant entities in Redis so that other workers and services can perform fast in-memory lookups without hitting the database on every request.

Responsibilities

For each Kafka change event the watcher:

  1. Determines the operation type (create, update, delete).
  2. Writes the updated entity to Redis (for create/update) or removes it (for delete).
  3. Applies availability checks — only active/available entities are cached.

Watched Entities

ModuleEntityRedis Usage
authGrantsABAC permission grants stored via abacl-redis RedisDriver
authAPTsAuth Personal Tokens cached for fast API key validation
domainClientsOAuth client records cached for token validation
identityUsersUser records cached for identity resolution
contextConfigsCQRS webhook configs read by the dispatcher
careerProductsProduct records cached for business logic lookups
conjointMessagesMessage records cached for real-time delivery
contentPostsPost records cached for content delivery

Grant Caching (ABAC)

Grants are handled specially through abacl-redis:

The isAvailable() check ensures only active, non-expired grants are stored. Inactive or expired grants are removed immediately.

Infrastructure Dependencies

DependencyUsage
KafkaConsumes MongoDB change stream events
RedisWrite target — all watched entities land here
MongoDBSource of truth (via Kafka change events)

Key Files

FilePurpose
modules/auth/grants/grants.service.tsABAC grant cache sync via abacl-redis
modules/auth/apts/apts.service.tsAPT (API key) cache sync
modules/domain/clients/clients.service.tsOAuth client cache sync
modules/identity/users/users.service.tsUser record cache sync
modules/context/configs/configs.service.tsCQRS config cache sync
modules/career/products/products.service.tsProduct cache sync
modules/conjoint/messages/messages.service.tsMessage cache sync
modules/content/posts/posts.service.tsPost cache sync