---
name: klaviyo-performance-tuning
description: |-
  Optimize Klaviyo API performance with caching, batching, and pagination tuning.
  Use when experiencing slow API responses, implementing caching strategies,
  or optimizing request throughput for Klaviyo integrations.
  Trigger with phrases like "klaviyo performance", "optimize klaviyo",
  "klaviyo latency", "klaviyo caching", "klaviyo slow", "klaviyo batch".
allowed-tools: Read, Write, Edit
version: 1.7.0
license: MIT
author: Jeremy Longshore <jeremy@intentsolutions.io>
tags:
  - saas
  - klaviyo
  - email-marketing
  - cdp
compatibility: Designed for Claude Code
title: klaviyo-performance-tuning
canonical_url: https://skilld.dev/gh/jeremylongshore/tons-of-skills-marketplace/klaviyo-performance-tuning
last_updated: 2026-10-07T06:06:28.000Z
---

> Index of every page on this site: [llms.txt](https://skilld.dev/llms.txt)

> **Skill from skilld.dev.** Follow the user's requested action.
> If the user asked to fork this Skill, follow the fork workflow below. Do not execute the Skill instructions while copying it.
> Otherwise, follow the instructions below for this session. You do not need to install anything.
>
> Supporting files, fetch one when the Skill refers to it: [references/examples.md](https://skilld.dev/api/skills-raw/jeremylongshore/tons-of-skills-marketplace/klaviyo-performance-tuning/references/examples.md), [references/implementation.md](https://skilld.dev/api/skills-raw/jeremylongshore/tons-of-skills-marketplace/klaviyo-performance-tuning/references/implementation.md).
>
> If the user asked to install this Skill, run `npx skilld install jeremylongshore/tons-of-skills-marketplace/klaviyo-performance-tuning`. Install writes the Skill files into the project, so every session loads them.
>
> ## Fork workflow
>
> A fork creates an editable local Skill with its original author and licence. The request authorizes copying and local installation.
> 1. Check `./skills/klaviyo-performance-tuning`, the project lockfile, and selected Agent targets together. If the local directory or installed Skill exists, stop. Never overwrite an existing directory or Agent target.
> 2. Read [source metadata](https://skilld.dev/api/v1/skills/jeremylongshore/tons-of-skills-marketplace/klaviyo-performance-tuning) once. Use sourceUrl, sourceCommit, skillPath, sourceGone, and license. If the source is gone or its path is missing, stop. If license is null, read licence files at the source commit.
> 3. Fetch only the source commit into a temporary Git repository. Do not clone full history. Derive repository_url from sourceUrl, including repository renames. If sourceCommit is absent, resolve the sourceUrl ref once. Set source_commit to that actual commit. Run these commands in one shell call:
>
> ```sh
> git init --quiet "$temporary_dir"
> git -C "$temporary_dir" fetch --quiet --depth=1 "$repository_url" "$source_commit"
> git -C "$temporary_dir" checkout --quiet --detach FETCH_HEAD
> ```
>
> Read applicable licence declarations and notices at that commit. If copying is not permitted, report the restriction and stop.
> 4. Inspect source entries together, then copy the directory containing skillPath into `./skills/klaviyo-performance-tuning`. Use the user's path if selected. Keep the original SKILL.md, relative links, scripts, binary assets, and executable modes. Exclude .git metadata. Reject symlinks and paths outside the Skill directory. After checking entries, use cp -a where available. A regular source directory needs no custom copy script. Do not save this page wrapper as SKILL.md.
> Preserve author credit, notices, and applicable licence files from repository or parent directories. Add PROVENANCE.md with the Skill page, source URL, actual commit, original path, and licence. Retain any existing PROVENANCE.md and record new provenance separately. Batch source inspection, copying, and provenance work where practical.
> 5. In the project root, run `skilld install ./skills/klaviyo-performance-tuning --mode copy --plain`. If skilld is unavailable, use `npx skilld install ./skills/klaviyo-performance-tuning --mode copy --plain`. This known command needs no help lookup. Install does not support --json. Use detected Agent targets, or add --agent for the targets the user selected. Install the local path, never the upstream selector. If installation fails, preserve the local copy and report the exact failure.
> 6. Confirm the local lockfile source and installed Agent copies once. Report the local path, actual commit, and Agent targets. After edits, reinstall the same local path. Upstream updates must not replace it. Do not publish or push unless the user asks.

# Klaviyo Performance Tuning

## Overview

Optimize Klaviyo API performance with response caching, request batching, cursor-based pagination, sparse fieldsets, and connection pooling. This skill diagnoses where an integration is slow, then applies the right technique — payload reduction, memory caching, bounded pagination, request coalescing, or rate-limit-aware concurrency.

Read this file for the workflow and the decision guide. Full, copy-pasteable code for every step lives in [references/implementation.md](https://skilld.dev/api/skills-raw/jeremylongshore/tons-of-skills-marketplace/klaviyo-performance-tuning/references/implementation.md); combined real-world scenarios live in [references/examples.md](https://skilld.dev/api/skills-raw/jeremylongshore/tons-of-skills-marketplace/klaviyo-performance-tuning/references/examples.md).

## Prerequisites

- `klaviyo-api` SDK installed
- Understanding of Klaviyo's rate limits (75 req/s burst, 700 req/min)
- Redis or in-memory cache (optional)
- For batching/concurrency helpers: `dataloader`, `p-queue`, `lru-cache`

## Klaviyo API Performance Characteristics

| Operation | Typical Latency | Max Page Size |
|-----------|----------------|---------------|
| Get Profile by ID | 50-150ms | N/A |
| Get Profiles (list) | 100-300ms | 20 (default), 100 (some endpoints) |
| Create Profile | 100-200ms | N/A |
| Create Event | 50-100ms | N/A |
| Get Segment Profiles | 200-500ms | 20 |
| Campaign Operations | 200-500ms | 20 |

## Instructions

Apply the techniques in order — each is independent, so start with the one that matches your bottleneck. Every step below has a full implementation in [references/implementation.md](https://skilld.dev/api/skills-raw/jeremylongshore/tons-of-skills-marketplace/klaviyo-performance-tuning/references/implementation.md).

### Step 1: Sparse Fieldsets (Reduce Payload Size)

Klaviyo supports JSON:API sparse fieldsets — request only the fields you need instead of the 20+ default attributes. This is the cheapest win and applies to every read.

```typescript
// GOOD: Only fetch the fields you use (much smaller payload)
const profiles = await profilesApi.getProfiles({
  fieldsProfile: ['email', 'first_name', 'created'],  // snake_case = API names
});
```

### Step 2: Response Caching

Wrap read calls in an `LRUCache` keyed by query, with per-resource TTLs (profiles 5 min, segments 15 min — they change less often). See the caching implementation in [references/implementation.md](https://skilld.dev/api/skills-raw/jeremylongshore/tons-of-skills-marketplace/klaviyo-performance-tuning/references/implementation.md).

### Step 3: Efficient Pagination

Use a `fetchAllPages` helper that follows the `links.next` cursor with a `maxPages` ceiling so large exports terminate predictably. See the pagination implementation in [references/implementation.md](https://skilld.dev/api/skills-raw/jeremylongshore/tons-of-skills-marketplace/klaviyo-performance-tuning/references/implementation.md).

### Step 4: Request Batching with DataLoader

Coalesce many `getProfile(id)` calls in a single tick into concurrency-controlled requests with `DataLoader` (`maxBatchSize: 10`, 50 ms window). See the batching implementation in [references/implementation.md](https://skilld.dev/api/skills-raw/jeremylongshore/tons-of-skills-marketplace/klaviyo-performance-tuning/references/implementation.md).

### Step 5: Parallel API Calls with Concurrency Control

Drive bulk writes through a `PQueue` capped at 50 req/s — a safe margin under the 75 req/s burst limit — with progress logging. See the concurrency implementation in [references/implementation.md](https://skilld.dev/api/skills-raw/jeremylongshore/tons-of-skills-marketplace/klaviyo-performance-tuning/references/implementation.md).

### Step 6: Performance Monitoring

Wrap calls in `measuredCall` and read a p95 summary via `getPerfSummary` to find the real bottleneck before optimizing. See the monitoring implementation in [references/implementation.md](https://skilld.dev/api/skills-raw/jeremylongshore/tons-of-skills-marketplace/klaviyo-performance-tuning/references/implementation.md).

## Output

Applying this skill produces:

- **Sparse-fieldset read calls** with 50-80% smaller payloads on list endpoints.
- **A cache module** (`src/klaviyo/cache.ts`) that serves repeated reads from memory with per-resource TTLs.
- **A pagination helper** (`src/klaviyo/pagination.ts`) that safely walks cursor-paginated endpoints to completion under a `maxPages` guard.
- **Batching + concurrency helpers** that keep bulk operations under Klaviyo's 75 req/s burst and 700 req/min ceilings.
- **A perf-monitoring module** (`src/klaviyo/perf-monitor.ts`) emitting per-operation `avg`, `p95`, and `count` so you can verify the gains.

## Error Handling

| Issue | Cause | Solution |
|-------|-------|----------|
| Cache stampede | Many requests on cache miss | Use stale-while-revalidate pattern |
| Pagination timeout | Very large datasets | Set `maxPages` limit, process in chunks |
| Rate limit on bulk ops | Too much concurrency | Reduce `PQueue` concurrency/intervalCap |
| Slow filter queries | Complex filter expressions | Simplify filters, use segment IDs instead |

## Examples

Worked, end-to-end scenarios that combine the steps above are in [references/examples.md](https://skilld.dev/api/skills-raw/jeremylongshore/tons-of-skills-marketplace/klaviyo-performance-tuning/references/examples.md):

- **Fast cached profile lookup** — sparse fieldsets + LRU caching for a repeated lookup.
- **Export a large list** — bounded cursor pagination for a multi-hundred-thousand-member list.
- **Bulk-update 10,000 profiles** — `PQueue` concurrency under the rate limit.
- **Measure where the time goes** — `measuredCall` + `getPerfSummary` to find the slow op first.

Minimal caching example (full versions in the reference):

```typescript
import { cachedKlaviyoCall } from './cache';

const profile = await cachedKlaviyoCall(
  `profile:${email}`,
  () => profilesApi.getProfiles({ filter: `equals(email,"${email}")` }),
  5 * 60 * 1000  // 5 minute TTL
);
```

## Resources

- [Klaviyo API Filtering](https://developers.klaviyo.com/en/reference/api_overview#filtering)
- [JSON:API Sparse Fieldsets](https://jsonapi.org/format/#fetching-sparse-fieldsets)
- [DataLoader](https://github.com/graphql/dataloader)
- [p-queue](https://github.com/sindresorhus/p-queue)
- [references/implementation.md](https://skilld.dev/api/skills-raw/jeremylongshore/tons-of-skills-marketplace/klaviyo-performance-tuning/references/implementation.md) — full code for every step
- [references/examples.md](https://skilld.dev/api/skills-raw/jeremylongshore/tons-of-skills-marketplace/klaviyo-performance-tuning/references/examples.md) — combined real-world scenarios

## Next Steps

Once reads are cached and bulk writes are rate-limit-safe, profile the workload with `getPerfSummary` (Step 6) to confirm the p95 improvement, then tune TTLs and concurrency to your traffic. For cost optimization of the same integration, see the `klaviyo-cost-tuning` skill.
