{
  "schemaVersion": "1.0",
  "item": {
    "slug": "dual-stream-architecture",
    "name": "Dual Stream Architecture",
    "source": "tencent",
    "type": "skill",
    "category": "效率提升",
    "sourceUrl": "https://clawhub.ai/wpank/dual-stream-architecture",
    "canonicalUrl": "https://clawhub.ai/wpank/dual-stream-architecture",
    "targetPlatform": "OpenClaw"
  },
  "install": {
    "downloadMode": "redirect",
    "downloadUrl": "/downloads/dual-stream-architecture",
    "sourceDownloadUrl": "https://wry-manatee-359.convex.site/api/v1/download?slug=dual-stream-architecture",
    "sourcePlatform": "tencent",
    "targetPlatform": "OpenClaw",
    "installMethod": "Manual import",
    "extraction": "Extract archive",
    "prerequisites": [
      "OpenClaw"
    ],
    "packageFormat": "ZIP package",
    "includedAssets": [
      "README.md",
      "SKILL.md"
    ],
    "primaryDoc": "SKILL.md",
    "quickSetup": [
      "Download the package from Yavira.",
      "Extract the archive and review SKILL.md first.",
      "Import or place the package into your OpenClaw setup."
    ],
    "agentAssist": {
      "summary": "Hand the extracted package to your coding agent with a concrete install brief instead of figuring it out manually.",
      "steps": [
        "Download the package from Yavira.",
        "Extract it into a folder your agent can access.",
        "Paste one of the prompts below and point your agent at the extracted folder."
      ],
      "prompts": [
        {
          "label": "New install",
          "body": "I downloaded a skill package from Yavira. Read SKILL.md from the extracted folder and install it by following the included instructions. Then review README.md for any prerequisites, environment setup, or post-install checks. Tell me what you changed and call out any manual steps you could not complete."
        },
        {
          "label": "Upgrade existing",
          "body": "I downloaded an updated skill package from Yavira. Read SKILL.md from the extracted folder, compare it with my current installation, and upgrade it while preserving any custom configuration unless the package docs explicitly say otherwise. Then review README.md for any prerequisites, environment setup, or post-install checks. Summarize what changed and any follow-up checks I should run."
        }
      ]
    },
    "sourceHealth": {
      "source": "tencent",
      "status": "healthy",
      "reason": "direct_download_ok",
      "recommendedAction": "download",
      "checkedAt": "2026-04-23T16:43:11.935Z",
      "expiresAt": "2026-04-30T16:43:11.935Z",
      "httpStatus": 200,
      "finalUrl": "https://wry-manatee-359.convex.site/api/v1/download?slug=4claw-imageboard",
      "contentType": "application/zip",
      "probeMethod": "head",
      "details": {
        "probeUrl": "https://wry-manatee-359.convex.site/api/v1/download?slug=4claw-imageboard",
        "contentDisposition": "attachment; filename=\"4claw-imageboard-1.0.1.zip\"",
        "redirectLocation": null,
        "bodySnippet": null
      },
      "scope": "source",
      "summary": "Source download looks usable.",
      "detail": "Yavira can redirect you to the upstream package for this source.",
      "primaryActionLabel": "Download for OpenClaw",
      "primaryActionHref": "/downloads/dual-stream-architecture"
    },
    "validation": {
      "installChecklist": [
        "Use the Yavira download entry.",
        "Review SKILL.md after the package is downloaded.",
        "Confirm the extracted package contains the expected setup assets."
      ],
      "postInstallChecks": [
        "Confirm the extracted package includes the expected docs or setup files.",
        "Validate the skill or prompts are available in your target agent workspace.",
        "Capture any manual follow-up steps the agent could not complete."
      ]
    },
    "downloadPageUrl": "https://openagent3.xyz/downloads/dual-stream-architecture",
    "agentPageUrl": "https://openagent3.xyz/skills/dual-stream-architecture/agent",
    "manifestUrl": "https://openagent3.xyz/skills/dual-stream-architecture/agent.json",
    "briefUrl": "https://openagent3.xyz/skills/dual-stream-architecture/agent.md"
  },
  "agentAssist": {
    "summary": "Hand the extracted package to your coding agent with a concrete install brief instead of figuring it out manually.",
    "steps": [
      "Download the package from Yavira.",
      "Extract it into a folder your agent can access.",
      "Paste one of the prompts below and point your agent at the extracted folder."
    ],
    "prompts": [
      {
        "label": "New install",
        "body": "I downloaded a skill package from Yavira. Read SKILL.md from the extracted folder and install it by following the included instructions. Then review README.md for any prerequisites, environment setup, or post-install checks. Tell me what you changed and call out any manual steps you could not complete."
      },
      {
        "label": "Upgrade existing",
        "body": "I downloaded an updated skill package from Yavira. Read SKILL.md from the extracted folder, compare it with my current installation, and upgrade it while preserving any custom configuration unless the package docs explicitly say otherwise. Then review README.md for any prerequisites, environment setup, or post-install checks. Summarize what changed and any follow-up checks I should run."
      }
    ]
  },
  "documentation": {
    "source": "clawhub",
    "primaryDoc": "SKILL.md",
    "sections": [
      {
        "title": "Dual-Stream Architecture",
        "body": "Publish events to Kafka (durability) and Redis Pub/Sub (real-time) simultaneously for systems needing both guaranteed delivery and instant updates."
      },
      {
        "title": "OpenClaw / Moltbot / Clawbot",
        "body": "npx clawhub@latest install dual-stream-architecture"
      },
      {
        "title": "When to Use",
        "body": "Event-driven systems needing both durability AND real-time\nWebSocket/SSE backends that push live updates\nDashboards showing events as they happen\nKafka consumers have lag but users expect instant updates"
      },
      {
        "title": "Core Pattern",
        "body": "type DualPublisher struct {\n    kafka  *kafka.Writer\n    redis  *redis.Client\n    logger *slog.Logger\n}\n\nfunc (p *DualPublisher) Publish(ctx context.Context, event Event) error {\n    // 1. Kafka: Critical path - must succeed\n    payload, _ := json.Marshal(event)\n    err := p.kafka.WriteMessages(ctx, kafka.Message{\n        Key:   []byte(event.SourceID),\n        Value: payload,\n    })\n    if err != nil {\n        return fmt.Errorf(\"kafka publish failed: %w\", err)\n    }\n\n    // 2. Redis: Best-effort - don't fail the operation\n    p.publishToRedis(ctx, event)\n\n    return nil\n}\n\nfunc (p *DualPublisher) publishToRedis(ctx context.Context, event Event) {\n    // Lightweight payload (full event in Kafka)\n    notification := map[string]interface{}{\n        \"id\":        event.ID,\n        \"type\":      event.Type,\n        \"source_id\": event.SourceID,\n    }\n\n    payload, _ := json.Marshal(notification)\n    channel := fmt.Sprintf(\"events:%s:%s\", event.SourceType, event.SourceID)\n\n    // Fire and forget - log errors but don't propagate\n    if err := p.redis.Publish(ctx, channel, payload).Err(); err != nil {\n        p.logger.Warn(\"redis publish failed\", \"error\", err)\n    }\n}"
      },
      {
        "title": "Architecture",
        "body": "┌──────────────┐     ┌─────────────────┐     ┌──────────────┐\n│   Ingester   │────▶│  DualPublisher  │────▶│    Kafka     │──▶ Event Processor\n│              │     │                 │     │  (durable)   │\n└──────────────┘     │                 │     └──────────────┘\n                     │                 │     ┌──────────────┐\n                     │                 │────▶│ Redis PubSub │──▶ WebSocket Gateway\n                     │                 │     │ (real-time)  │\n                     └─────────────────┘     └──────────────┘"
      },
      {
        "title": "Channel Naming Convention",
        "body": "events:{source_type}:{source_id}\n\nExamples:\n- events:user:octocat      - Events for user octocat\n- events:repo:owner/repo   - Events for a repository\n- events:org:microsoft     - Events for an organization"
      },
      {
        "title": "Batch Publishing",
        "body": "For high throughput:\n\nfunc (p *DualPublisher) PublishBatch(ctx context.Context, events []Event) error {\n    // 1. Batch to Kafka\n    messages := make([]kafka.Message, len(events))\n    for i, event := range events {\n        payload, _ := json.Marshal(event)\n        messages[i] = kafka.Message{\n            Key:   []byte(event.SourceID),\n            Value: payload,\n        }\n    }\n\n    if err := p.kafka.WriteMessages(ctx, messages...); err != nil {\n        return fmt.Errorf(\"kafka batch failed: %w\", err)\n    }\n\n    // 2. Redis: Pipeline for efficiency\n    pipe := p.redis.Pipeline()\n    for _, event := range events {\n        channel := fmt.Sprintf(\"events:%s:%s\", event.SourceType, event.SourceID)\n        notification, _ := json.Marshal(map[string]interface{}{\n            \"id\":   event.ID,\n            \"type\": event.Type,\n        })\n        pipe.Publish(ctx, channel, notification)\n    }\n    \n    if _, err := pipe.Exec(ctx); err != nil {\n        p.logger.Warn(\"redis batch failed\", \"error\", err)\n    }\n\n    return nil\n}"
      },
      {
        "title": "Decision Tree",
        "body": "RequirementStreamWhyMust not lose eventKafka onlyAck required, replicatedUser sees immediatelyRedis onlySub-ms deliveryBoth durability + real-timeDual streamThis patternHigh volume (>10k/sec)Kafka, batch RedisRedis can bottleneckMany subscribers per channelRedis + local fan-outDon't hammer Redis"
      },
      {
        "title": "Related Skills",
        "body": "Meta-skill: ai/skills/meta/realtime-dashboard/ — Complete realtime dashboard guide\nwebsocket-hub-patterns — WebSocket gateway\nbackend/service-layer-architecture — Service integration"
      },
      {
        "title": "NEVER Do",
        "body": "NEVER fail on Redis errors — Redis is best-effort. Log and continue.\nNEVER send full payload to Redis — Send IDs only, clients fetch from API.\nNEVER create one Redis channel per event — Use source-level channels.\nNEVER skip Kafka for \"unimportant\" events — All events go to Kafka for replay.\nNEVER use Redis Pub/Sub for persistence — Messages are fire-and-forget."
      },
      {
        "title": "Edge Cases",
        "body": "CaseSolutionRedis downLog warning, continue with Kafka onlyClient connects mid-streamQuery API for recent events, then subscribeHigh channel cardinalityUse wildcard patterns or aggregate channelsKafka backpressureBuffer in memory with timeout, fail if fullNeed event replayConsume from Kafka from offset, not Redis"
      }
    ],
    "body": "Dual-Stream Architecture\n\nPublish events to Kafka (durability) and Redis Pub/Sub (real-time) simultaneously for systems needing both guaranteed delivery and instant updates.\n\nInstallation\nOpenClaw / Moltbot / Clawbot\nnpx clawhub@latest install dual-stream-architecture\n\nWhen to Use\nEvent-driven systems needing both durability AND real-time\nWebSocket/SSE backends that push live updates\nDashboards showing events as they happen\nKafka consumers have lag but users expect instant updates\nCore Pattern\ntype DualPublisher struct {\n    kafka  *kafka.Writer\n    redis  *redis.Client\n    logger *slog.Logger\n}\n\nfunc (p *DualPublisher) Publish(ctx context.Context, event Event) error {\n    // 1. Kafka: Critical path - must succeed\n    payload, _ := json.Marshal(event)\n    err := p.kafka.WriteMessages(ctx, kafka.Message{\n        Key:   []byte(event.SourceID),\n        Value: payload,\n    })\n    if err != nil {\n        return fmt.Errorf(\"kafka publish failed: %w\", err)\n    }\n\n    // 2. Redis: Best-effort - don't fail the operation\n    p.publishToRedis(ctx, event)\n\n    return nil\n}\n\nfunc (p *DualPublisher) publishToRedis(ctx context.Context, event Event) {\n    // Lightweight payload (full event in Kafka)\n    notification := map[string]interface{}{\n        \"id\":        event.ID,\n        \"type\":      event.Type,\n        \"source_id\": event.SourceID,\n    }\n\n    payload, _ := json.Marshal(notification)\n    channel := fmt.Sprintf(\"events:%s:%s\", event.SourceType, event.SourceID)\n\n    // Fire and forget - log errors but don't propagate\n    if err := p.redis.Publish(ctx, channel, payload).Err(); err != nil {\n        p.logger.Warn(\"redis publish failed\", \"error\", err)\n    }\n}\n\nArchitecture\n┌──────────────┐     ┌─────────────────┐     ┌──────────────┐\n│   Ingester   │────▶│  DualPublisher  │────▶│    Kafka     │──▶ Event Processor\n│              │     │                 │     │  (durable)   │\n└──────────────┘     │                 │     └──────────────┘\n                     │                 │     ┌──────────────┐\n                     │                 │────▶│ Redis PubSub │──▶ WebSocket Gateway\n                     │                 │     │ (real-time)  │\n                     └─────────────────┘     └──────────────┘\n\nChannel Naming Convention\nevents:{source_type}:{source_id}\n\nExamples:\n- events:user:octocat      - Events for user octocat\n- events:repo:owner/repo   - Events for a repository\n- events:org:microsoft     - Events for an organization\n\nBatch Publishing\n\nFor high throughput:\n\nfunc (p *DualPublisher) PublishBatch(ctx context.Context, events []Event) error {\n    // 1. Batch to Kafka\n    messages := make([]kafka.Message, len(events))\n    for i, event := range events {\n        payload, _ := json.Marshal(event)\n        messages[i] = kafka.Message{\n            Key:   []byte(event.SourceID),\n            Value: payload,\n        }\n    }\n\n    if err := p.kafka.WriteMessages(ctx, messages...); err != nil {\n        return fmt.Errorf(\"kafka batch failed: %w\", err)\n    }\n\n    // 2. Redis: Pipeline for efficiency\n    pipe := p.redis.Pipeline()\n    for _, event := range events {\n        channel := fmt.Sprintf(\"events:%s:%s\", event.SourceType, event.SourceID)\n        notification, _ := json.Marshal(map[string]interface{}{\n            \"id\":   event.ID,\n            \"type\": event.Type,\n        })\n        pipe.Publish(ctx, channel, notification)\n    }\n    \n    if _, err := pipe.Exec(ctx); err != nil {\n        p.logger.Warn(\"redis batch failed\", \"error\", err)\n    }\n\n    return nil\n}\n\nDecision Tree\nRequirement\tStream\tWhy\nMust not lose event\tKafka only\tAck required, replicated\nUser sees immediately\tRedis only\tSub-ms delivery\nBoth durability + real-time\tDual stream\tThis pattern\nHigh volume (>10k/sec)\tKafka, batch Redis\tRedis can bottleneck\nMany subscribers per channel\tRedis + local fan-out\tDon't hammer Redis\nRelated Skills\nMeta-skill: ai/skills/meta/realtime-dashboard/ — Complete realtime dashboard guide\nwebsocket-hub-patterns — WebSocket gateway\nbackend/service-layer-architecture — Service integration\nNEVER Do\nNEVER fail on Redis errors — Redis is best-effort. Log and continue.\nNEVER send full payload to Redis — Send IDs only, clients fetch from API.\nNEVER create one Redis channel per event — Use source-level channels.\nNEVER skip Kafka for \"unimportant\" events — All events go to Kafka for replay.\nNEVER use Redis Pub/Sub for persistence — Messages are fire-and-forget.\nEdge Cases\nCase\tSolution\nRedis down\tLog warning, continue with Kafka only\nClient connects mid-stream\tQuery API for recent events, then subscribe\nHigh channel cardinality\tUse wildcard patterns or aggregate channels\nKafka backpressure\tBuffer in memory with timeout, fail if full\nNeed event replay\tConsume from Kafka from offset, not Redis"
  },
  "trust": {
    "sourceLabel": "tencent",
    "provenanceUrl": "https://clawhub.ai/wpank/dual-stream-architecture",
    "publisherUrl": "https://clawhub.ai/wpank/dual-stream-architecture",
    "owner": "wpank",
    "version": "1.0.0",
    "license": null,
    "verificationStatus": "Indexed source record"
  },
  "links": {
    "detailUrl": "https://openagent3.xyz/skills/dual-stream-architecture",
    "downloadUrl": "https://openagent3.xyz/downloads/dual-stream-architecture",
    "agentUrl": "https://openagent3.xyz/skills/dual-stream-architecture/agent",
    "manifestUrl": "https://openagent3.xyz/skills/dual-stream-architecture/agent.json",
    "briefUrl": "https://openagent3.xyz/skills/dual-stream-architecture/agent.md"
  }
}