Skip to content

Data and Events

Two common misreadings during an incident: that data lives only in the database, and that notifications are sent synchronously. Neither is true.

AutoMigrate registers 69 models at boot. By purpose they fall into five groups:

GroupMain tables
Identityusers, credentials, user_sessions, user_mfa, api_keys, oauth_accounts, roles, role_permissions, groups, group_members, group_permissions, invites, banned, user_follows, user_blocks, login_histories, security_events
Contentposts, contents, spaces, tags, post_tags, drafts, revisions, uploads, announcements, topic_read_states, badges, user_badges
Engagementcontent_likes, post_favorites, watches, notifications, conversations, conversation_members, messages, check_ins
Governancereports, content_moderations, moderation_rules, moderation_configs, motions, motion_votes, audit_logs
Configsettings, meta, permissions, space_role_permissions, xp_rules, xp_streak_bonuses, trust_levels, xp_adjustments, gate_rules, gate_domain_defaults, webhooks, webhook_deliveries, backups, plugins, import_maps, mcp_servers

Two boundaries matter. AutoMigrate only adds — dropping columns, changing types and moving data never happen automatically. And the SQL scripts are not executed for you: files in app/server/db/migrations/ are run by hand, and each opens with background, whether it is optional, whether it is idempotent, and its compatibility caveats.

users.total_xp, trust_level and level_metrics have exactly one writer, TrustService.Recompute. Anything else that updates them gets overwritten by the next recompute.

KV is not a decorative cache — remove it and the site stops working (sessions, rate limits and settings all depend on it). An empty NATS_URL aborts startup instead of falling back to local memory.

KeyTTLPurpose
sess:<sid>remaining session lifetimesession read-through; user_sessions stays authoritative
rl:<ip>:<policy>window (usually 1 min)per-endpoint IP budget, e.g. rl:1.2.3.4:login
rl:ratelimit:<ip>windowglobal per-IP ceiling (policy global)
apikey_rl:<keyID>windowper-key API budget
setting:<key>60 s (miss marker 10 s)settings cache; writes delete the key
oauth:<state> / oauth_state:<state>5 / 10 minCSRF state for social login and gateway OAuth, single use
ban:<userID> / ban:<userID>:<spaceID>30 sglobal / per-space ban cache
vc:<postID>until flushedview-count delta, flushed to SQL every 60 s
notif:unread:<userID>5 minunread counter behind the SSE push
emailcode:<purpose>:<email>email_code_ttl (600 s)email verification code

Keys are hex-encoded before they reach JetStream, and per-key TTL uses a companion <bucket>_ttl bucket — NATS does not show you the plaintext key.

The bus is NATS core pub/sub with one queue subscription per event type: each event is consumed by exactly one instance, which then fans it out to every local subscriber. The in-process buffer holds 100 events with 4 workers; when it is full the event is dropped and counted in feedchamber_eventbus_dropped_total. Drops are permanent — the missing notification or XP never arrives later.

EventPublished byConsumed byEffect
post.createdpost creationwebhooks, async moderationwith moderation_mode=async, decides whether the post is queued for review
post.closedclose/reopenwebhooksexternal sync
content.creatednew commentwebhooksexternal sync
content.repliedcomment or replynotifications, webhooksone comment notification
content.likedcomment likenotifications, webhooksone like notification
content.watchedwatched topic updatednotifications, webhooksone watch notification
user.createdregistrationwebhooksuser.registered is emitted alongside as a legacy alias
user.followedfollownotifications, webhooksone follow notification
user.mentioned@mentionnotifications, webhooksone mention notification
report.createdreport filedwebhooksexternal ticketing
moderation.decidedapprove/rejectwebhooksdecision is approved or rejected
motion.created / motion.resolvedmotion opened / settlednotifications, webhooksone motion notification on the same SSE channel

The trace context travels in the traceparent header, so a consumer’s log lines join the HTTP request that published the event.

One comment can hit three fan-out paths at once: post (or parent comment) author → @mentions → topic watchers. All three share a single notified set and honour that priority, so one comment produces exactly one notification. A new fan-out step must take the same set, or recipients start getting duplicates. Commenting on your own post notifies nobody.

With more than one instance, config written on one instance must take effect on the others. Three pub/sub channels do that:

ChannelWritten byInvalidates
perm:syncrole / space / group permission changesthe permission cache (role → codes, space hierarchy)
trust:syncXP rules, level definitionsthe XP config snapshot
gate:syncgate rules and domain defaultsthe gate rule snapshot

Settings have no broadcast channel. setting:<key> is a 60-second read cache; the writer deletes its own key and other instances converge within 60 seconds. “Changed a setting, one instance still behaves the old way, correct a minute later” is by design.

  • POST /api/v1/notifications/stream writes an SSE comment : keepalive every 15 seconds. An idle stream carries no bytes, so any intermediary with a read timeout cuts it — nginx defaults to 60 s and the disconnect was measured at 61 s. The frontend parser only reacts to data: lines, so the comment cannot surface as an event.
  • POST /api/v1/realtime/stream emits a heartbeat event every 15 seconds.

deploy/nginx/nginx.conf carries a dedicated SSE location (buffering off, timeout 3600 s).

终端窗口
curl -s localhost:9091/metrics | grep feedchamber_eventbus_publish_total
curl -s localhost:8080/api/v1/health | grep kvstore

Missing notifications: check whether feedchamber_eventbus_dropped_total is rising, then feedchamber_sse_write_failures_total. Changes that will not apply: confirm which instance you changed, wait 60 seconds, then look for a WARN about a failed sync subscription.