# Paddle catalog api stale while revalidate

> SWR pattern on Paddle product catalog edge pipeline. For "paddle catalog api stale while revalidate", store PADDLE_API_KEY in Secret Vault, call https://api.paddle.com/prices?per_page=20 from a Worker, and let Frontend / Web hit only https://realcomposer.com/v1/workspace/paddle-catalog-stale-while-revalidate with an rc_live_ client token. Enable 300s GET cache only when query params identify the resource.

- Canonical page: https://realcomposer.com/recipes/paddle-catalog-stale-while-revalidate
- Client platform: Frontend / Web
- Upstream services: Paddle
- Category: Edge Caching & Rate Limits
- JSON version: https://realcomposer.com/recipes/paddle-catalog-stale-while-revalidate.json
- Install in RealComposer (free plan, pre-fills this pipeline): https://realcomposer.com/dashboard/pipelines/new?recipe=paddle-catalog-stale-while-revalidate&via=agent

## Problem: Uncached Paddle spikes cost and latency

Every Frontend / Web visitor can trigger a fresh Paddle 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. **Store upstream credentials in Secret Vault**: Store PADDLE_API_KEY in the vault. Frontend / Web never embeds the raw secret, only a revocable rc_live_ client token.

2. **Set headers, mapping, and cache TTL**: Configure headersTemplate to inject vault secrets, target https://api.paddle.com/prices?per_page=20, and Add output mapping fields that mirror the JSON contract your screen already expects.

3. **Call from Frontend / Web**: Authorize with Bearer rc_live_ and fetch the mapped JSON contract your UI already expects.

```
const res = await fetch('https://realcomposer.com/v1/workspace/paddle-catalog-stale-while-revalidate', {
  headers: { 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": "Paddle catalog api stale while revalidate",
  "method": "GET",
  "cacheTtlSeconds": 300,
  "authMode": "client_token",
  "steps": [
    {
      "stepKey": "paddle",
      "upstreamUrlTemplate": "https://api.paddle.com/prices?per_page=20",
      "httpMethod": "GET",
      "headersTemplate": {
        "Authorization": "Bearer {{secrets.PADDLE_API_KEY}}"
      },
      "timeoutMs": 3000
    }
  ],
  "outputMapping": {
    "version": 1,
    "fields": [
      {
        "targetPath": "subscriptionId",
        "sourcePath": "data.id",
        "type": "string",
        "sourceStep": "paddle"
      },
      {
        "targetPath": "status",
        "sourcePath": "data.status",
        "type": "string",
        "sourceStep": "paddle"
      }
    ]
  }
}
```

## Call the pipeline

```bash
curl -X GET "https://realcomposer.com/v1/workspace/paddle-catalog-stale-while-revalidate" \
  -H "Authorization: Bearer rc_live_client_token"
```

## Payload before and after

Raw upstream response:

```json
{
  "requestId": "req_paddle-c",
  "upstreamLatencyMs": 142,
  "audit": {
    "region": "edge",
    "trace": "paddle-catalog-stale-while-revalidate"
  },
  "payload": {
    "id": "sample_id",
    "status": "active",
    "nested": {
      "tags": [
        "demo"
      ],
      "internal": true
    },
    "unused_blob": {
      "foo": "bar",
      "bar": "baz"
    }
  }
}
```

Slimmed RealComposer response:

```json
{
  "subscriptionId": "sample",
  "status": "sample"
}
```

## FAQ

### Can Frontend / Web call Paddle without holding the production key?

Store PADDLE_API_KEY for paddle-catalog-stale-while-revalidate. Frontend / Web never sees decrypted values.

### Does POST traffic get cached?

paddle-catalog-stale-while-revalidate: only GET requests cache (300s on caches.default). Key is workspace slug plus sorted query params, not Authorization.

### What happens if an upstream step times out?

Allowed origins on the paddle-catalog-stale-while-revalidate client token restrict which domains may call the edge URL.
