{
  "slug": "cache-mailchimp-api-avoid-rate-limits",
  "title": "Cache mailchimp api to stay under rate limits",
  "metaDescription": "Cache mailchimp api to stay under rate limits. Shield Mailchimp with 300s GET edge cache; cache key uses query params on.",
  "headline": "Marketing site list previews without hammering API",
  "category": "caching",
  "categoryLabel": "Edge Caching & Rate Limits",
  "urgency": 9,
  "clientPlatform": "JavaScript / HTML",
  "upstreamServices": [
    "Mailchimp"
  ],
  "searchIntentQuery": "cache mailchimp api to stay under rate limits",
  "directAnswerSummary": "Shared edge cache for popular list metadata endpoints. For \"cache mailchimp api to stay under rate limits\", store MAILCHIMP_BASIC_AUTH in Secret Vault, call https://{{secrets.MAILCHIMP_DC}}.api.mailchimp.com/3.0/lists/{{query.listId}}/members?count=10 from a Worker, and let JavaScript / HTML hit only https://realcomposer.com/v1/workspace/cache-mailchimp-api-avoid-rate-limits with an rc_live_ client token. Enable 300s GET cache only when query params identify the resource.",
  "problem": {
    "title": "Uncached Mailchimp spikes cost and latency",
    "explanation": "Every JavaScript / HTML visitor can trigger a fresh Mailchimp call. Bursts exhaust per-minute quotas even when data changes slowly.",
    "risks": [
      "Thundering herds after cache expiry on the origin",
      "Analytics skewed by client-side retry storms",
      "Support tickets blaming \"API downtime\" during spikes"
    ]
  },
  "solutionSteps": [
    {
      "stepNumber": 1,
      "title": "Store upstream credentials in Secret Vault",
      "description": "Store MAILCHIMP_BASIC_AUTH in the vault. JavaScript / HTML never embeds the raw secret, only a revocable rc_live_ client token."
    },
    {
      "stepNumber": 2,
      "title": "Configure upstream steps and output mapping",
      "description": "Use GET against https://{{secrets.MAILCHIMP_DC}}.api.mailchimp.com/3.0/lists/{{query.listId}}/members?count=10. Allowed origins on the client token should match set cache ttl to 300s so repeat gets with the same query string hit caches.default."
    },
    {
      "stepNumber": 3,
      "title": "Call from JavaScript / HTML",
      "description": "Allowed origins on the token should list every JavaScript / HTML host that calls this URL.",
      "codeSnippet": "const data = await fetch('https://realcomposer.com/v1/workspace/cache-mailchimp-api-avoid-rate-limits', {\n  headers: { Authorization: 'Bearer rc_live_your_token' }\n}).then(r => r.json());"
    }
  ],
  "pipelineConfig": {
    "name": "Cache mailchimp api to stay under rate limits",
    "method": "GET",
    "cacheTtlSeconds": 300,
    "authMode": "client_token",
    "steps": [
      {
        "stepKey": "mailchimp",
        "upstreamUrlTemplate": "https://{{secrets.MAILCHIMP_DC}}.api.mailchimp.com/3.0/lists/{{query.listId}}/members?count=10",
        "httpMethod": "GET",
        "headersTemplate": {
          "Authorization": "Basic {{secrets.MAILCHIMP_BASIC_AUTH}}"
        },
        "timeoutMs": 3000
      }
    ],
    "outputMapping": {
      "version": 1,
      "fields": [
        {
          "targetPath": "memberId",
          "sourcePath": "members.0.id",
          "type": "string",
          "sourceStep": "mailchimp"
        },
        {
          "targetPath": "email",
          "sourcePath": "members.0.email_address",
          "type": "string",
          "sourceStep": "mailchimp"
        },
        {
          "targetPath": "status",
          "sourcePath": "members.0.status",
          "type": "string",
          "sourceStep": "mailchimp"
        }
      ]
    }
  },
  "sampleBloatedInput": {
    "requestId": "req_cache-ma",
    "upstreamLatencyMs": 142,
    "audit": {
      "region": "edge",
      "trace": "cache-mailchimp-api-avoid-rate-limits"
    },
    "payload": {
      "id": "sample_id",
      "status": "active",
      "nested": {
        "tags": [
          "demo"
        ],
        "internal": true
      },
      "unused_blob": {
        "foo": "bar",
        "bar": "baz"
      }
    }
  },
  "sampleSlimmedOutput": {
    "memberId": "sample",
    "email": "sample",
    "status": "sample"
  },
  "curlSnippet": "curl -X GET \"https://realcomposer.com/v1/workspace/cache-mailchimp-api-avoid-rate-limits\" \\\n  -H \"Authorization: Bearer rc_live_client_token\"",
  "faqs": [
    {
      "question": "Can JavaScript / HTML call Mailchimp without holding the production key?",
      "answer": "Log request IDs for cache-mailchimp-api-avoid-rate-limits, not raw Mailchimp payloads, because upstream bodies may include PII."
    },
    {
      "question": "How do I forward JSON bodies to POST upstreams?",
      "answer": "cache-mailchimp-api-avoid-rate-limits forwards client JSON to POST upstreams unchanged; secrets interpolate only in URLs and header templates."
    },
    {
      "question": "What happens if an upstream step times out?",
      "answer": "Allowed origins on the cache-mailchimp-api-avoid-rate-limits client token restrict which domains may call the edge URL."
    }
  ],
  "relatedRecipeSlugs": [
    "cache-airtable-avoid-rate-limits",
    "avoid-third-party-api-rate-limits"
  ],
  "updatedAt": "2026-11-20",
  "links": {
    "page": "https://realcomposer.com/recipes/cache-mailchimp-api-avoid-rate-limits",
    "markdown": "https://realcomposer.com/recipes/cache-mailchimp-api-avoid-rate-limits.md",
    "json": "https://realcomposer.com/recipes/cache-mailchimp-api-avoid-rate-limits.json",
    "install": "https://realcomposer.com/dashboard/pipelines/new?recipe=cache-mailchimp-api-avoid-rate-limits&via=agent"
  }
}