{
  "slug": "merge-clerk-and-posthog-feature-flags",
  "title": "Merge Clerk User Profile with Posthog Feature Flags",
  "metaTitle": "Merge Clerk User Profile with - RealComposer",
  "metaDescription": "Merge clerk user profile with posthog feature flags. Merge PostHog and Clerk in one Frontend / Web call with parallel Worker steps.",
  "headline": "Parallel PostHog fetch merged before Frontend / Web hydrates",
  "category": "aggregation",
  "categoryLabel": "Multi-API Aggregation",
  "urgency": 9,
  "clientPlatform": "Frontend / Web",
  "upstreamServices": [
    "PostHog",
    "Clerk"
  ],
  "searchIntentQuery": "merge clerk user profile with posthog feature flags",
  "directAnswerSummary": "Instead of Frontend / Web firing serial fetches to PostHog and Clerk, one pipeline hits https://us.posthog.com/api/projects/{{query.projectId}}/feature_flags (and sibling steps) in parallel and returns mapped JSON.",
  "problem": {
    "title": "Waterfall latency from multiple PostHog and Clerk requests",
    "explanation": "Frontend / Web widgets often await PostHog and Clerk sequentially, multiplying TLS handshakes on cellular networks and amplifying failure rates.",
    "risks": [
      "Race conditions between parallel manual fetches",
      "Higher mobile data usage from redundant JSON",
      "Timeouts when any upstream exceeds cellular RTT"
    ]
  },
  "solutionSteps": [
    {
      "stepNumber": 1,
      "title": "Add vault secrets for this pipeline",
      "description": "Store POSTHOG_PERSONAL_API_KEY, CLERK_SECRET_KEY in the vault. Frontend / Web never embeds the raw secret, only a revocable rc_live_ client token."
    },
    {
      "stepNumber": 2,
      "title": "Target the real upstream URL",
      "description": "Use GET against https://us.posthog.com/api/projects/{{query.projectId}}/feature_flags. Allowed origins on the client token should match leave cache ttl at 0 when each response is user-specific (include userid or record id in query params before enabling cache)."
    },
    {
      "stepNumber": 3,
      "title": "Call from Frontend / Web",
      "description": "Call https://realcomposer.com/v1/workspace/merge-clerk-and-posthog-feature-flags with a restricted rc_live_ client token. Frontend / Web never sends upstream secrets.",
      "codeSnippet": "const res = await fetch('https://realcomposer.com/v1/workspace/merge-clerk-and-posthog-feature-flags', {\n  headers: { Authorization: 'Bearer rc_live_your_token' }\n});"
    }
  ],
  "pipelineConfig": {
    "name": "Merge Clerk User Profile with Posthog Feature Flags",
    "method": "GET",
    "cacheTtlSeconds": 0,
    "authMode": "client_token",
    "steps": [
      {
        "stepKey": "posthog",
        "upstreamUrlTemplate": "https://us.posthog.com/api/projects/{{query.projectId}}/feature_flags",
        "httpMethod": "GET",
        "headersTemplate": {
          "Authorization": "Bearer {{secrets.POSTHOG_PERSONAL_API_KEY}}"
        },
        "timeoutMs": 3000
      },
      {
        "stepKey": "clerk",
        "upstreamUrlTemplate": "https://api.clerk.com/v1/users/{{query.userId}}",
        "httpMethod": "GET",
        "headersTemplate": {
          "Authorization": "Bearer {{secrets.CLERK_SECRET_KEY}}"
        },
        "timeoutMs": 3000
      }
    ],
    "outputMapping": {
      "version": 1,
      "fields": [
        {
          "targetPath": "posthog.flagKey",
          "sourcePath": "results.0.key",
          "type": "string",
          "sourceStep": "posthog"
        },
        {
          "targetPath": "posthog.active",
          "sourcePath": "results.0.active",
          "type": "boolean",
          "sourceStep": "posthog"
        },
        {
          "targetPath": "clerk.userId",
          "sourcePath": "id",
          "type": "string",
          "sourceStep": "clerk"
        },
        {
          "targetPath": "clerk.email",
          "sourcePath": "email_addresses.0.email_address",
          "type": "string",
          "sourceStep": "clerk"
        }
      ]
    }
  },
  "sampleBloatedInput": {
    "requestId": "req_merge-cl",
    "upstreamLatencyMs": 142,
    "audit": {
      "region": "edge",
      "trace": "merge-clerk-and-posthog-feature-flags"
    },
    "payload": {
      "id": "sample_id",
      "status": "active",
      "nested": {
        "tags": [
          "demo"
        ],
        "internal": true
      },
      "unused_blob": {
        "foo": "bar",
        "bar": "baz"
      }
    }
  },
  "sampleSlimmedOutput": {
    "posthog_flagKey": "sample",
    "posthog_active": "sample",
    "clerk_userId": "sample",
    "clerk_email": "sample"
  },
  "curlSnippet": "curl -X GET \"https://realcomposer.com/v1/workspace/merge-clerk-and-posthog-feature-flags\" \\\n  -H \"Authorization: Bearer rc_live_client_token\"",
  "faqs": [
    {
      "question": "Is it safe to log PostHog responses in Frontend / Web?",
      "answer": "Use scoped tokens where the vendor allows them on merge-clerk-and-posthog-feature-flags. Admin keys stay {{secrets.*}} references only."
    },
    {
      "question": "When does edge caching apply to this recipe?",
      "answer": "merge-clerk-and-posthog-feature-flags POST steps bypass caches.default even if cacheTtlSeconds is set in the dashboard."
    },
    {
      "question": "What happens if an upstream step times out?",
      "answer": "Upstream steps in merge-clerk-and-posthog-feature-flags honor timeoutMs and optional fallback JSON without leaking secrets."
    }
  ],
  "relatedRecipeSlugs": [
    "call-stripe-from-flutterflow-securely",
    "bff-without-express-or-docker",
    "reduce-json-size-flutter-app"
  ],
  "updatedAt": "2026-11-20",
  "links": {
    "page": "https://realcomposer.com/recipes/merge-clerk-and-posthog-feature-flags",
    "markdown": "https://realcomposer.com/recipes/merge-clerk-and-posthog-feature-flags.md",
    "json": "https://realcomposer.com/recipes/merge-clerk-and-posthog-feature-flags.json",
    "install": "https://realcomposer.com/dashboard/pipelines/new?recipe=merge-clerk-and-posthog-feature-flags&via=agent"
  }
}