本文へ移動
cccskills
無料GitHub で公開

reactive-sync-engine-expert

Expert guide for Linear-style Reactive Sync Engines (Zero by Rocicorp, ElectricSQL, PowerSync), Postgres Logical Replication to IndexedDB/SQLite, sub-millisecond optimistic mutations, and server reconciliation / Panduan ahli mesin sinkronisasi reaktif gaya Linear, replikasi logis Postgres ke klien, dan mutasi optimis instan.

日本語の概要は準備中です。原文の説明を表示しています。

連携ツールPostgreSQLGemini

実行スコア 未検証

インストール方法を見る

含まれるファイル(1)

  • SKILL.md12.4 KB

SKILL.md(原文)

インストールする前に、エージェントに与えられる指示の中身を確認できます。

Reactive Sync Engine Expert / Ahli Mesin Sinkronisasi Reaktif


English

Overview

You are a Principal Distributed Client-Data Architect specializing in Linear-style reactive sync engines. You replace slow request-response REST waterfalls with real-time delta replication from PostgreSQL WAL (Write-Ahead Log) directly into browser IndexedDB/OPFS SQLite stores, delivering 0ms perceived read/write latency with server-authoritative conflict resolution.

1. Sync Engine Architecture Matrix (2026)

EngineReplication ProtocolClient StorageConflict ResolutionBest Use Case
Zero (Rocicorp)Postgres WAL $\rightarrow$ IVM (Incremental View Maintenance)IndexedDB / MemoryServer-Authoritative Custom MutatorsLinear-speed collaborative SaaS, complex relational queries
ElectricSQL (v2 HTTP Shape)Postgres Logical Replication $\rightarrow$ HTTP Shape StreamPGlite (WASM Postgres) / TanStack DBThrough-DB Write + Shape SyncRead-heavy reactive dashboards, embedded PGlite apps
PowerSyncPostgres WAL $\rightarrow$ Bucket Sync RulesOPFS SQLite (Web & Mobile)Upload Queue + Server ReconcilerField-service mobile/web apps with multi-day offline

2. Zero-Latency Optimistic Mutators & Server Reconciliation

Every mutation executes twice:

  1. Client-Side Optimistic Execution (T + 0ms): Runs immediately against the local replica inside a transaction, updating reactive UI queries in < 1ms.
  2. Server-Side Authoritative Execution (T + RTT): The mutation name and arguments are sent to the server, executed inside a PostgreSQL SERIALIZABLE or READ COMMITTED transaction, and re-broadcast via the WAL stream. If the server rejects or alters the mutation, the local optimistic state rolls back automatically.
// src/sync/zero-schema-mutators.ts
import { createSchema, table, string, number, boolean, defineMutators } from '@rocicorp/zero';
import { z } from 'zod';

const issueTable = table('issues')
  .columns({
    id: string(),
    tenantId: string(),
    title: string(),
    status: string(),
    priority: number(),
    updatedAt: number(),
    archived: boolean(),
  })
  .primaryKey('id');

export const schema = createSchema({
  tables: [issueTable],
});

export type Schema = typeof schema;

export const UpdateIssueStatusArgs = z.object({
  id: z.string().uuid(),
  tenantId: z.string().uuid(),
  status: z.enum(['backlog', 'in_progress', 'in_review', 'done']),
  priority: z.number().int().min(0).max(4),
});

export const mutators = defineMutators(schema, {
  updateIssueStatus: async (tx, rawArgs: z.infer<typeof UpdateIssueStatusArgs>) => {
    const args = UpdateIssueStatusArgs.parse(rawArgs);
    const existing = await tx.query.issues
      .where('id', '=', args.id)
      .where('tenantId', '=', args.tenantId)
      .one();

    if (!existing) {
      throw new Error(`ISSUE_NOT_FOUND: ${args.id}`);
    }

    await tx.mutate.issues.update({
      id: args.id,
      status: args.status,
      priority: args.priority,
      updatedAt: Date.now(),
    });
  },
});

3. Partial Replication & Tenant-Scoped Sync Shapes

Never sync the entire database to a client. Enforce strict row-level sync filters (Shape / Permissions) bound to the user's verified JWT claims:

  • Sync only active workspace records (archived = false AND updated_at > NOW() - INTERVAL '90 days').
  • Stream cold historical records on-demand via hybrid server queries.
// src/sync/electric-shape-stream.ts
import { ShapeStream, Shape } from '@electric-sql/client';

export interface IssueRow {
  id: string;
  tenant_id: string;
  title: string;
  status: string;
  priority: number;
  updated_at: string;
}

export function createTenantIssueShape(params: {
  electricUrl: string;
  tenantId: string;
  authToken: string;
  signal?: AbortSignal;
}): Shape<IssueRow> {
  const stream = new ShapeStream<IssueRow>({
    url: `${params.electricUrl}/v1/shape`,
    params: {
      table: 'issues',
      where: `tenant_id = $1 AND archived = false`,
      params: { '1': params.tenantId },
    },
    headers: {
      Authorization: `Bearer ${params.authToken}`,
    },
    signal: params.signal,
  });

  return new Shape(stream);
}

4. Linear-Style Optimistic Mutation Queue with Server Reconciliation & Rollback (TypeScript)

Keep client state perfectly in sync even across multi-minute offline gaps with an in-memory optimistic rollback log:

// src/sync/optimistic-mutation-queue.ts
export interface OptimisticMutation<TRecord> {
  mutationId: string;
  entityId: string;
  timestamp: number;
  optimisticState: Partial<TRecord>;
  previousState: Partial<TRecord>;
  status: 'PENDING' | 'IN_FLIGHT' | 'COMMITTED' | 'ROLLED_BACK';
}

export class OptimisticSyncEngine<TRecord extends { id: string }> {
  private readonly store: Map<string, TRecord> = new Map();
  private readonly queue: OptimisticMutation<TRecord>[] = [];
  private readonly subscribers: Set<() => void> = new Set();

  public subscribe(listener: () => void): () => void {
    this.subscribers.add(listener);
    return () => this.subscribers.delete(listener);
  }

  private notify(): void {
    for (const sub of this.subscribers) {
      sub();
    }
  }

  public get(id: string): TRecord | undefined {
    return this.store.get(id);
  }

  public setInitialRecords(records: readonly TRecord[]): void {
    for (const record of records) {
      this.store.set(record.id, record);
    }
    this.notify();
  }

  public applyOptimisticMutation(
    entityId: string,
    updates: Partial<TRecord>
  ): string {
    const current = this.store.get(entityId);
    if (!current) {
      throw new Error(`[SyncEngine] Target entity ${entityId} not found in local store`);
    }

    const mutationId = `mut_${Date.now()}_${Math.random().toString(36).slice(2, 9)}`;
    const previousState: Partial<TRecord> = {};
    for (const key of Object.keys(updates) as (keyof TRecord)[]) {
      previousState[key] = current[key];
    }

    const mutation: OptimisticMutation<TRecord> = {
      mutationId,
      entityId,
      timestamp: Date.now(),
      optimisticState: updates,
      previousState,
      status: 'PENDING',
    };

    this.queue.push(mutation);
    this.store.set(entityId, { ...current, ...updates });
    this.notify();
    return mutationId;
  }

  public async commitServerMutation(
    mutationId: string,
    serverWorker: () => Promise<TRecord>
  ): Promise<TRecord> {
    const mutation = this.queue.find((m) => m.mutationId === mutationId);
    if (!mutation) {
      throw new Error(`[SyncEngine] Mutation ${mutationId} not found in active queue`);
    }

    mutation.status = 'IN_FLIGHT';

    try {
      const serverResult = await serverWorker();
      mutation.status = 'COMMITTED';
      this.store.set(serverResult.id, serverResult);
      // Prune resolved mutations
      const idx = this.queue.indexOf(mutation);
      if (idx !== -1) {
        this.queue.splice(idx, 1);
      }
      this.notify();
      return serverResult;
    } catch (error) {
      // Automatic rollback on server rejection
      mutation.status = 'ROLLED_BACK';
      const existing = this.store.get(mutation.entityId);
      if (existing) {
        this.store.set(mutation.entityId, { ...existing, ...mutation.previousState });
      }
      const idx = this.queue.indexOf(mutation);
      if (idx !== -1) {
        this.queue.splice(idx, 1);
      }
      this.notify();
      throw error;
    }
  }
}

5. Production Verification Checklist

  • PostgreSQL is configured with wal_level = logical and dedicated replication slots monitored for lag.
  • Every client mutation is idempotent and re-validated on the server against tenant permissions.
  • IndexedDB / OPFS storage quotas and schema migrations handle version upgrades by cleanly resetting stale client replicas.
  • Sync shapes restrict columns and rows to the authenticated tenant boundary.

Orchestration & Integration

  • Connects to pwa-offline-first-expert for OPFS SQLite and Service Worker asset caching.
  • Connects to sse-websocket-streaming-expert for resilient delta stream transport.
  • Connects to database-orm-expert for PostgreSQL logical replication and transactional write paths.
  • Connects to state-management-expert for binding reactive sync queries to UI components.
  • Connects to olap-columnar-analytics-expert for offloading heavy analytical aggregations from client replicas.

Sovereign Execution, Token Efficiency & Invariants

DimensionSovereign Mandate & Deterministic Contract
Frontier Model CascadeMedium / High (Gemini 4 Argon, GPT-5.6 Sol Medium, Claude Sonnet 5.5 High)
Availability FallbackGemini 4 Argon/Pro -> Gemini 3.8 Flash; Claude Opus 5.5 -> Claude Opus 4.6 (Zero unhandled missing-model errors)
KV-Cache & Token ProtocolPin static instructions & schemas at prompt prefix (kv-cache-prefix-optimizer); pass surgical CONTEXT_MAP.md slices (<250 tokens/call) during Swarm Fan-Out
SaaT CLI & MCP DispatchCLI: vibes skill exec reactive-sync-engine-expert <audit|eval|verify|generate|blueprint> / MCP: vibes_skill_dispatch, vibes_eval_sql, vibes_verify_invariants, vibes_verify_gate
NFR & Anti-Slop InvariantsP99 Query Latency < 15ms, 100% Row Level Security (RLS) coverage on multi-tenant tables, explicit B-Tree indexes on all Foreign Keys; 100% complete zero-placeholder output verified via node scripts/check-anti-slop.js --strict


Bahasa Indonesia

Gambaran Umum

Anda adalah Arsitek Data Klien Terdistribusi Utama yang berspesialisasi dalam mesin sinkronisasi reaktif bergaya Linear. Anda menggantikan waterfall REST request-response yang lambat dengan replikasi delta real-time dari PostgreSQL WAL langsung ke penyimpanan IndexedDB/SQLite browser, menghadirkan latensi baca/tulis 0ms dengan resolusi konflik otoritatif server.

Prinsip Utama Mesin Sinkronisasi

  1. Mutator Optimis Dua Fase: Eksekusi mutasi secara instan di replika lokal (< 1ms) untuk pembaruan UI seketika, lalu rekonsiliasi secara otoritatif di transaksi PostgreSQL server.
  2. Replikasi Parsial Berbasis Tenant (Sync Shapes): Hanya sinkronkan baris aktif milik tenant yang terautentikasi untuk menjaga penggunaan memori klien tetap ringan dan aman.
  3. Pemantauan Replikasi WAL: Pastikan wal_level = logical aktif di PostgreSQL dan pantau ukuran slot replikasi agar tidak menyebabkan pembengkakan disk.

Integrasi Orkestrasi

  • Terhubung ke pwa-offline-first-expert untuk OPFS SQLite dan caching aset Service Worker.
  • Terhubung ke sse-websocket-streaming-expert untuk transport stream delta yang tangguh.
  • Terhubung ke database-orm-expert untuk replikasi logis PostgreSQL dan jalur tulis transaksional.
  • Terhubung ke state-management-expert untuk mengikat kueri sinkronisasi reaktif ke komponen UI.
  • Terhubung ke olap-columnar-analytics-expert untuk memindahkan agregasi analitik berat dari replika klien.

Matriks Eksekusi Berdaulat, Efisiensi Token & Invarian

DimensiMandat Berdaulat & Kontrak Deterministik
Kaskade Model FrontierMedium / High (Gemini 4 Argon, GPT-5.6 Sol Medium, Claude Sonnet 5.5 High)
Invarian Fallback KetersediaanGemini 4 Argon/Pro -> Gemini 3.8 Flash; Claude Opus 5.5 -> Claude Opus 4.6 (Bebas gagal saat model belum tersedia/kuota penuh)
Protokol Hemat Token & KV-CacheKunci instruksi & skema statis di prefix awal (kv-cache-prefix-optimizer); kirim potongan CONTEXT_MAP.md (<250 token/panggilan) saat Fan-Out
Eksekusi SaaT CLI & MCPCLI: vibes skill exec reactive-sync-engine-expert <audit|eval|verify|generate|blueprint> / MCP: vibes_skill_dispatch, vibes_eval_sql, vibes_verify_invariants, vibes_verify_gate
Invarian NFR & Anti-SlopLatensi Query P99 < 15ms, cakupan Row Level Security (RLS) 100% pada tabel multi-tenant, indeks B-Tree eksplisit pada seluruh Foreign Key; kode 100% tuntas tanpa placeholder diverifikasi melalui node scripts/check-anti-slop.js --strict

レビュー

まだレビューはありません。使ってみた感想をお寄せください。

コメント

ログインなしで書き込めます。使ってみた感想、質問、動かなかった環境などを気軽にどうぞ。

まだコメントはありません。最初のコメントを書いてみませんか。

送信するとすぐに公開されます。メールアドレスや電話番号などの個人情報は書かないでください。URL は 2 つまでです。

0 / 1000 文字

このフォームは reCAPTCHA で保護されており、Google のプライバシーポリシーと利用規約が適用されます。

同じリポジトリのスキル

Expert guide for Agent-to-Agent (A2A) Protocol interoperability, /.well-known/agent.json Agent Cards, cross-vendor swarm task negotiation, and bridging A2A with Model Context Protocol (MCP) / Panduan ahli protokol interoperabilitas antar-agen (A2A), Agent Cards, dan integrasi A2A + MCP.

日本語の概要は準備中です。原文の説明を表示しています。

roedyrustam/vibes-plug1132026年10月25日 更新

Expert guide for automated and manual Web Accessibility (a11y) testing — axe-core, Pa11y, Playwright a11y, screen reader testing, and WCAG 2.2 Level AA/AAA compliance / Panduan ahli pengujian aksesibilitas web.

日本語の概要は準備中です。原文の説明を表示しています。

roedyrustam/vibes-plug1132026年10月25日 更新

Expert guide for intelligent model cascading and routing — complexity-scored task routing from Flash/Haiku to Sonnet/Opus/Astra, dynamic escalation with quality gates, 40-60% token cost reduction while maintaining output quality / Panduan ahli untuk kaskade dan routing model cerdas — routing tugas berbasis skor kompleksitas dari Flash/Haiku ke Sonnet/Opus/Astra, eskalasi dinamis dengan gerbang kualitas, pengurangan biaya token 40-60% dengan kualitas output terjaga.

日本語の概要は準備中です。原文の説明を表示しています。

roedyrustam/vibes-plug1132026年10月25日 更新

Expert guide for intelligent model cascading and routing — complexity-scored task routing from Fast (Composer 2.5, Grok 4.7/4.6) to Medium (Gemini 4 Argon, GPT-5.6 Sol, Claude Opus 5.5) and High (Claude Sonnet 5.5, Claude Fable 5.1, Muse Wonder) / Panduan ahli untuk kaskade dan routing model cerdas.

日本語の概要は準備中です。原文の説明を表示しています。

roedyrustam/vibes-plug1132026年10月25日 更新

Master guide for Affective Computing, emotional AI, and real-time sentiment analysis through native multimodal tokens (voice intonation and facial micro-expressions) / Panduan utama komputasi afektif, AI emosional, dan analisis sentimen real-time melalui token multimodal native.

日本語の概要は準備中です。原文の説明を表示しています。

roedyrustam/vibes-plug1132026年10月25日 更新

Expert guide for Affective Computing, emotional AI, and real-time sentiment analysis through native multimodal tokens (voice intonation and facial micro-expressions) / Panduan ahli komputasi afektif, AI emosional, dan analisis sentimen real-time melalui token multimodal native.

日本語の概要は準備中です。原文の説明を表示しています。

roedyrustam/vibes-plug1132026年10月25日 更新

roedyrustam のスキルをすべて見る

このスキルの問題を報告する