Lewati ke konten utama

Desain Teknis

Komponen​

KomponenTanggung jawab
WorkerCommonAppModuleMemuat konfigurasi, database, startup barrier, bootstrap, dan modul realtime.
KvBootstrapServiceMenjalankan full bootstrap lalu membuka startup barrier.
KvInitServiceMembaca daftar tabel dan mengisi cache awal.
KvCacheTableServiceMendengarkan perubahan metadata kv_cache_table.
KvCacheTableItemServiceMenambah/menghapus subscription CDC secara dinamis untuk tabel terdaftar.
KvCacheSyncServiceMengorkestrasi query database, operasi cache, dan publish event sinkronisasi.
KvCacheServiceMenyediakan operasi Redis row, index, serta global:config.
StartupBarrierServiceMenahan komponen realtime sampai bootstrap selesai.

Relasi sistem​

Stream dan subject​

StreamSubjectPemakaian
PG_CDC_EVENTSpgcdc.public.kv_cache_tablePerubahan registrasi tabel cache.
PG_CDC_EVENTSpgcdc.public.<table>Perubahan row pada setiap tabel terdaftar.
CONFIG_EVENTSconfig.sync.initSnapshot global:config setelah bootstrap.
CONFIG_EVENTSconfig.sync.changedPerubahan satu row atau hasil full sync satu tabel.
CONFIG_EVENTSconfig.sync.forceDidaftarkan, tetapi belum digunakan oleh worker ini.

Kedua stream memakai file storage, satu replica, retention berbasis limits, dan batas max_bytes 2 GiB. CONFIG_EVENTS juga memiliki max_age 30 hari.

Kontrak event keluar​

config.sync.init membawa:

{ type: 'init', snapshot: Record<string, Record<string, any>>, syncedAt: string }

config.sync.changed membawa salah satu bentuk:

// Perubahan row
{ type: 'row', cacheName, tableName, id, operation: 'c' | 'u' | 'd', data?, changedAt }

// Full sync tabel
{ type: 'table', cacheName, tableName, operation: 'sync', data, changedAt }

Teknologi​

TeknologiFungsi
NestJS 11Lifecycle, dependency injection, dan application context worker.
TypeORM 0.3 + pgAkses PostgreSQL datacore_db.
Redis + ioredisPenyimpanan cache.
NATS.js 2.29JetStream consumer dan publisher.
TypeScript 5.7Implementasi dan build.