# Firebase api rate limit avoid with edge caching

> Edge absorbs repeated profile lookups across users. For "firebase api rate limit avoid with edge caching", 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 FlutterFlow hit only https://realcomposer.com/v1/workspace/avoid-firebase-api-rate-limits-edge with an rc_live_ client token. Enable 180s GET cache only when query params identify the resource.

- Canonical page: https://realcomposer.com/recipes/avoid-firebase-api-rate-limits-edge
- Client platform: FlutterFlow
- Upstream services: Firebase
- Category: Edge Caching & Rate Limits
- JSON version: https://realcomposer.com/recipes/avoid-firebase-api-rate-limits-edge.json
- Install in RealComposer (free plan, pre-fills this pipeline): https://realcomposer.com/dashboard/pipelines/new?recipe=avoid-firebase-api-rate-limits-edge&via=agent

## Problem: Uncached Firebase spikes cost and latency

Every FlutterFlow visitor can trigger a fresh Firebase call. Bursts exhaust per-minute quotas even when data changes slowly.

- Thundering herds after cache expiry on the origin
- Analytics skewed by client-side retry storms
- Support tickets blaming "API downtime" during spikes

## Solution steps

1. **Bind vault keys to the Worker**: Store FIREBASE_ACCESS_TOKEN in the vault. FlutterFlow never embeds the raw secret, only a revocable rc_live_ client token.

2. **Target the real upstream URL**: Configure headersTemplate to inject vault secrets, target https://firestore.googleapis.com/v1/projects/{{query.projectId}}/databases/(default)/documents/{{query.collection}}/{{query.docId}}, and Add output mapping fields that mirror the JSON contract your screen already expects.

3. **Wire the FlutterFlow API Call**: Call https://realcomposer.com/v1/workspace/avoid-firebase-api-rate-limits-edge with a restricted rc_live_ client token. FlutterFlow never sends upstream secrets.

```
// FlutterFlow API Call
URL: https://realcomposer.com/v1/workspace/avoid-firebase-api-rate-limits-edge
Header Authorization: Bearer rc_live_your_token
```

## Pipeline config

Import this config into a RealComposer pipeline. `{{secrets.NAME}}` values are read from the encrypted Secret Vault at request time, so the client never sees them.

```json
{
  "name": "Firebase api rate limit avoid with edge caching",
  "method": "GET",
  "cacheTtlSeconds": 180,
  "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"
      }
    ]
  }
}
```

## Call the pipeline

```bash
curl -X GET "https://realcomposer.com/v1/workspace/avoid-firebase-api-rate-limits-edge" \
  -H "Authorization: Bearer rc_live_client_token"
```

## Payload before and after

Raw upstream response:

```json
{
  "requestId": "req_avoid-fi",
  "upstreamLatencyMs": 142,
  "audit": {
    "region": "edge",
    "trace": "avoid-firebase-api-rate-limits-edge"
  },
  "payload": {
    "id": "sample_id",
    "status": "active",
    "nested": {
      "tags": [
        "demo"
      ],
      "internal": true
    },
    "unused_blob": {
      "foo": "bar",
      "bar": "baz"
    }
  }
}
```

Slimmed RealComposer response:

```json
{
  "docName": "sample",
  "fields": "sample"
}
```

## FAQ

### What should FlutterFlow store instead of Firebase secrets?

Log request IDs for avoid-firebase-api-rate-limits-edge, not raw Firebase payloads, because upstream bodies may include PII.

### How do I forward JSON bodies to POST upstreams?

Cache key for avoid-firebase-api-rate-limits-edge: internal edge-cache path plus sorted query. Identical params hit; vary userId per user.

### How do I rotate upstream credentials?

Rotate vault secrets for avoid-firebase-api-rate-limits-edge anytime; clients keep the same rc_live_ token.
