{
  "slug": "reduce-firebase-firestore-json-size",
  "title": "How to reduce firebase firestore json payload size",
  "metaTitle": "reduce firebase firestore json - RealComposer",
  "metaDescription": "How to reduce firebase firestore json payload size. Map only UI fields from Firebase before Flutter / React Native / Swift parses JSON.",
  "headline": "Flatten Firestore REST documents for lists",
  "category": "slimmer",
  "categoryLabel": "Payload Slimmer",
  "urgency": 9,
  "clientPlatform": "Flutter / React Native / Swift",
  "upstreamServices": [
    "Firebase"
  ],
  "searchIntentQuery": "how to reduce firebase firestore json payload size",
  "directAnswerSummary": "Strips document names revision metadata and map noise at edge. For \"how to reduce firebase firestore json payload size\", store FIREBASE_ACCESS_TOKEN in Secret Vault, call https://firestore.googleapis.com/v1/projects/{{query.projectId}}/databases/(default)/documents/{{query.collection}}/{{query.docId}} from a Worker, and let Flutter / React Native / Swift hit only https://realcomposer.com/v1/workspace/reduce-firebase-firestore-json-size with an rc_live_ client token.",
  "problem": {
    "title": "Firebase JSON bloat on Flutter / React Native / Swift",
    "explanation": "Oversized Firebase payloads inflate parse time and mobile data charges for Flutter / React Native / Swift users.",
    "risks": [
      "Main-thread JSON parse stalls on low-end phones",
      "Accidentally exposing PII fields to the client",
      "Downstream components re-render on unused keys"
    ]
  },
  "solutionSteps": [
    {
      "stepNumber": 1,
      "title": "Add vault secrets for this pipeline",
      "description": "Add FIREBASE_ACCESS_TOKEN to RealComposer Secret Vault. Values decrypt only inside the Cloudflare Worker that calls the upstream."
    },
    {
      "stepNumber": 2,
      "title": "Set headers, mapping, and cache TTL",
      "description": "Use GET against https://firestore.googleapis.com/v1/projects/{{query.projectId}}/databases/(default)/documents/{{query.collection}}/{{query.docId}}. 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 Flutter / React Native / Swift",
      "description": "Call https://realcomposer.com/v1/workspace/reduce-firebase-firestore-json-size with a restricted rc_live_ client token. Flutter / React Native / Swift never sends upstream secrets.",
      "codeSnippet": "const res = await fetch('https://realcomposer.com/v1/workspace/reduce-firebase-firestore-json-size', {\n  headers: { Authorization: 'Bearer rc_live_your_token' }\n});"
    }
  ],
  "pipelineConfig": {
    "name": "How to reduce firebase firestore json payload size",
    "method": "GET",
    "cacheTtlSeconds": 0,
    "authMode": "client_token",
    "steps": [
      {
        "stepKey": "firebase",
        "upstreamUrlTemplate": "https://firestore.googleapis.com/v1/projects/{{query.projectId}}/databases/(default)/documents/{{query.collection}}/{{query.docId}}",
        "httpMethod": "GET",
        "headersTemplate": {
          "Authorization": "Bearer {{secrets.FIREBASE_ACCESS_TOKEN}}"
        },
        "timeoutMs": 3000
      }
    ],
    "outputMapping": {
      "version": 1,
      "fields": [
        {
          "targetPath": "docName",
          "sourcePath": "name",
          "type": "string",
          "sourceStep": "firebase"
        },
        {
          "targetPath": "fields",
          "sourcePath": "fields",
          "type": "object",
          "sourceStep": "firebase"
        }
      ]
    }
  },
  "sampleBloatedInput": {
    "requestId": "req_reduce-f",
    "upstreamLatencyMs": 142,
    "audit": {
      "region": "edge",
      "trace": "reduce-firebase-firestore-json-size"
    },
    "payload": {
      "id": "sample_id",
      "status": "active",
      "nested": {
        "tags": [
          "demo"
        ],
        "internal": true
      },
      "unused_blob": {
        "foo": "bar",
        "bar": "baz"
      }
    }
  },
  "sampleSlimmedOutput": {
    "docName": "sample",
    "fields": "sample"
  },
  "curlSnippet": "curl -X GET \"https://realcomposer.com/v1/workspace/reduce-firebase-firestore-json-size\" \\\n  -H \"Authorization: Bearer rc_live_client_token\"",
  "faqs": [
    {
      "question": "Can Flutter / React Native / Swift call Firebase without holding the production key?",
      "answer": "Point Flutter / React Native / Swift at /recipes/reduce-firebase-firestore-json-size edge URL. RealComposer answers OPTIONS with Access-Control headers for allowed origins."
    },
    {
      "question": "Does POST traffic get cached?",
      "answer": "reduce-firebase-firestore-json-size keeps cache TTL at 0 because it uses POST upstream calls or per-user responses. Add ids to query strings before enabling GET cache."
    },
    {
      "question": "What happens if an upstream step times out?",
      "answer": "Rotate vault secrets for reduce-firebase-firestore-json-size anytime; clients keep the same rc_live_ token."
    }
  ],
  "relatedRecipeSlugs": [
    "reduce-json-size-flutter-app",
    "flatten-nested-json-api-response"
  ],
  "updatedAt": "2026-11-20",
  "links": {
    "page": "https://realcomposer.com/recipes/reduce-firebase-firestore-json-size",
    "markdown": "https://realcomposer.com/recipes/reduce-firebase-firestore-json-size.md",
    "json": "https://realcomposer.com/recipes/reduce-firebase-firestore-json-size.json",
    "install": "https://realcomposer.com/dashboard/pipelines/new?recipe=reduce-firebase-firestore-json-size&via=agent"
  }
}