Skip to content

Watcher ​

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

The watcher keeps two read-side stores in sync with MongoDB. It consumes change stream events from Kafka and writes or removes the relevant entities — grants, APTs, OAuth clients, users and CQRS configs in Redis, so other workers and services can look them up without hitting the database on every request; products, messages and posts in Elasticsearch, where the search endpoints query them.

Responsibilities ​

For each Kafka change event the watcher:

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

Watched Entities ​

ModuleEntityStore and usage
authGrantsRedis — ABAC permission grants stored via abacl-redis RedisDriver
authAPTsRedis — Auth Personal Tokens cached for fast API key validation
domainClientsRedis — OAuth client records cached for token validation
identityUsersRedis — user records cached for identity resolution
contextConfigsRedis — CQRS webhook configs read by the dispatcher
careerProductsElasticsearch — career products index, queried by career/products search
conjointMessagesElasticsearch — conjoint messages index, queried by conjoint/messages search
contentPostsElasticsearch — content posts index, queried by content/posts search

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 for grants, APTs, clients, users and configs
ElasticsearchWrite target for products, messages and posts (index names carry ELASTIC_PREFIX)
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 search-index sync
modules/conjoint/messages/messages.service.tsMessage search-index sync
modules/content/posts/posts.service.tsPost search-index sync