andrueandersoncs/claude-skill-effect-ts
Overview
This skill explains how Effect optimizes API calls through batching, caching, and deduplication. It shows how to define request types and resolvers, enable automatic batching, and use built-in caching utilities like Effect.cached and the Cache service. The goal is to eliminate N+1 request patterns and reduce redundant network or database work.
How this skill works
Effect inspects request operations and can aggregate many individual requests into a single batched resolver call, allowing one network/database call to satisfy multiple logical requests. It also memoizes effect results and request outcomes within a query context, preventing duplicate concurrent work and enabling TTL-based or manual invalidation. You can opt in or out of batching and provide custom caches or resolvers with access to contextual services.
When to use it
- When facing N+1 query problems across loops or forEach operations
- When multiple callers request the same resource concurrently and you want deduplication
- When API or DB supports batch endpoints to reduce round trips
- When you need short-term memoization of expensive computations or network calls
- When you want fine-grained control over cache TTL, capacity, or invalidation
Best practices
- Use batched RequestResolvers at API boundaries to group related IDs into a single call
- Prefer Effect.cached or cachedWithTTL for inexpensive, read-heavy values to reduce repeated fetches
- Set TTLs to balance freshness and performance; use invalidate hooks for known changes
- Rely on automatic request deduplication within a query context to avoid duplicate inflight work
- Disable batching or request caching selectively for operations that must run independently
Example use cases
- Batching user lookups when iterating todos to avoid N+1 requests to /api/users
- Using RequestResolver.makeBatched to POST an array of ids and distribute results to individual requests
- Caching application config with Effect.cached so subsequent reads are instantaneous
- CachedWithTTL for current user data with automatic expiry after a short interval
- Creating a Cache service to control capacity, TTL, manual invalidation, and statistics
FAQ
Batched resolvers map results back to each original request, preserving per-request success or failure semantics. Ensure your batch endpoint returns results in a stable mapping or include identifiers in responses.
How do I force fresh data despite caching?
Use cachedInvalidateWithTTL to manually invalidate, or create/attach a custom cache and call invalidate. You can also disable request caching with Effect.withRequestCaching(false).
13 skills
This skill helps you optimize API usage by automatically batching requests and caching results to reduce N+1 queries.
This skill helps you understand and work with Effect's Streams API, including creation, transformation, backpressure, and consumption of real-time data.
This skill fetches and explains Effect-TS API docs from the official site, returning function signatures, parameters, and usage examples.
This skill helps you understand and manage Effect's Runtime execution, including default and managed runtimes, services, and configuration.
This skill helps you write robust pattern-matching with Effect Match, ensuring exhaustive, type-safe branches and minimal imperative code.
This skill helps you manage resources safely with acquireRelease, scope, and finalizers, ensuring cleanup even on errors or interruption.
This skill helps you reason about Effect error handling, distinguish failures, and implement typed, recoverable errors and defects.
This skill helps you integrate and orchestrate AI/LLM services with type-safe tooling, execution planning, and structured outputs for robust AI apps.
This skill helps you understand and use Effect platform abstractions for HTTP, filesystem, key-value storage, and terminal I/O across environments.
This skill helps you manage effect configuration safely by loading, validating, and composing environment variables and JSON config.
This skill helps you create and compose Effect programs in TypeScript, guiding you through creation, composition, and running of Effects.
This skill helps you understand and implement scheduling patterns, retry policies, and backoff strategies using Effect.
This skill helps you understand Effect's built-in data types and structures, enabling precise reasoning about Option, Either, Cause, Exit, and more.