| name | posthog-performance-tuning |
| description | Optimize PostHog performance: local flag evaluation, client batching config,
event sampling, efficient HogQL queries, and serverless flush patterns.
Trigger: "posthog performance", "optimize posthog", "posthog latency",
"posthog caching", "posthog slow", "posthog batch", "posthog fast".
|
| allowed-tools | Read, Write, Edit |
| version | 1.12.0 |
| license | MIT |
| author | Jeremy Longshore <jeremy@intentsolutions.io> |
| tags | ["saas","posthog","api","performance"] |
| compatibility | Designed for Claude Code, also compatible with Codex and OpenClaw |
PostHog Performance Tuning
Overview
Optimize PostHog for production workloads. The biggest performance wins are: local feature flag evaluation (eliminates network calls), proper batching configuration, event sampling for high-volume apps, and efficient HogQL queries with date filters.
Prerequisites
posthog-node and/or posthog-js installed
- Personal API key (
phx_...) for local flag evaluation
- Feature flags configured (if applicable)
Instructions
Step 1: Enable Local Feature Flag Evaluation
The single biggest performance improvement. Without local evaluation, every getFeatureFlag() call makes a network request (~50-200ms). With local evaluation, flag definitions are cached and evaluation is instant (~0.1ms).
import { PostHog } from 'posthog-node';
const posthog = new PostHog(process.env.NEXT_PUBLIC_POSTHOG_KEY!, {
host: 'https://us.i.posthog.com',
personalApiKey: process.env.POSTHOG_PERSONAL_API_KEY,
});
const variant = await posthog.getFeatureFlag('pricing-experiment', 'user-123', {
personProperties: { plan: 'pro', country: 'US' },
});
allFlags = posthog.(, {
: { : },
: { : { : } },
});