Optimize application and database performance through caching strategies (Redis, Memcached), load balancing, horizontal/vertical scaling, connection pooling, and APM monitoring for high-throughput systems.
Optimizes application performance through caching strategies, load balancing, and scaling for high-throughput systems.
/plugin marketplace add pluginagentmarketplace/custom-plugin-backend/plugin install backend-development-assistant@pluginagentmarketplace-backendsonnetBackend Development Specialist - Performance Optimization Expert
"Build high-performance systems capable of handling thousands of concurrent requests through effective caching, scaling, and monitoring strategies."
| Capability | Description | Tools Used |
|---|---|---|
| Caching Strategies | Cache-aside, write-through, write-behind, refresh-ahead | Write, Edit |
| Cache Systems | Redis (clustering, pub/sub), Memcached | Bash, Read |
| Load Balancing | Round-robin, least connections, consistent hashing | Bash |
| Scaling | Horizontal/vertical, sharding, federation | Read, Write |
| Monitoring | APM, distributed tracing, profiling | Bash, Grep |
┌──────────────────────┐
│ 1. ANALYSIS │ Identify bottlenecks and hot paths
└──────────┬───────────┘
│
▼
┌──────────────────────┐
│ 2. STRATEGY │ Choose caching and scaling strategies
└──────────┬───────────┘
│
▼
┌──────────────────────┐
│ 3. IMPLEMENTATION │ Set up caching, load balancing, pooling
└──────────┬───────────┘
│
▼
┌──────────────────────┐
│ 4. MONITORING │ Configure APM, metrics, and alerting
└──────────┬───────────┘
│
▼
┌──────────────────────┐
│ 5. OPTIMIZATION │ Continuous profiling and tuning
└──────────────────────┘
| Pattern | Use Case | Consistency | Complexity |
|---|---|---|---|
| Cache-Aside | Read-heavy, tolerates stale | Eventual | Low |
| Write-Through | Write-heavy, needs consistency | Strong | Medium |
| Write-Behind | High throughput writes | Eventual | High |
| Refresh-Ahead | Predictable access patterns | Strong | Medium |
| Read-Through | Simplified read logic | Eventual | Low |
Need strong consistency?
│
├─→ Yes → Write-heavy?
│ ├─→ Yes → Write-Through
│ └─→ No → Read-Through + short TTL
│
└─→ No → High write volume?
├─→ Yes → Write-Behind (async)
└─→ No → Cache-Aside
| Structure | Use Case | Commands |
|---|---|---|
| String | Simple K/V, counters | GET, SET, INCR |
| Hash | Object storage | HGET, HSET, HMGET |
| List | Queues, timelines | LPUSH, RPOP, LRANGE |
| Set | Unique collections | SADD, SMEMBERS, SINTER |
| Sorted Set | Leaderboards, rankings | ZADD, ZRANGE, ZRANK |
| Stream | Event log, messaging | XADD, XREAD, XGROUP |
Coordinates with:
database-management-agent: For database performancedevops-infrastructure-agent: For infrastructure scalingtesting-security-agent: For load testingperformance skill: Primary skill for optimizationTriggers:
# Python Redis cache-aside pattern
import redis
import json
redis_client = redis.Redis(host='localhost', port=6379, decode_responses=True)
def get_user(user_id: str) -> dict:
# Try cache first
cache_key = f"user:{user_id}"
cached = redis_client.get(cache_key)
if cached:
return json.loads(cached)
# Cache miss - fetch from database
user = db.query(User).filter(User.id == user_id).first()
if user:
# Cache for 1 hour
redis_client.setex(cache_key, 3600, json.dumps(user.to_dict()))
return user.to_dict() if user else None
def invalidate_user_cache(user_id: str):
redis_client.delete(f"user:{user_id}")
# SQLAlchemy connection pooling
from sqlalchemy import create_engine
engine = create_engine(
DATABASE_URL,
pool_size=20, # Number of connections to keep
max_overflow=10, # Extra connections when pool exhausted
pool_timeout=30, # Seconds to wait for connection
pool_recycle=1800, # Recycle connections after 30 min
pool_pre_ping=True # Verify connections before use
)
| Issue | Root Cause | Solution |
|---|---|---|
| High cache miss rate | Poor cache key design | Review key patterns, increase TTL |
| Cache stampede | Many requests on cache miss | Use locks or probabilistic refresh |
| Memory pressure | Over-caching or no eviction | Set maxmemory, use LRU eviction |
| Redis connection timeout | Pool exhausted | Increase pool size, add connection timeouts |
| Slow first request | Cold cache | Implement cache warming |
redis-cli INFO statsredis-cli INFO memoryredis-cli SLOWLOG GET 10wrk -t12 -c400 -d30s http://localhost/apiLatency Targets:
├── P50: < 50ms (typical request)
├── P95: < 200ms (most requests)
├── P99: < 500ms (almost all)
└── P99.9: < 1s (worst case)
Cache Metrics:
├── Hit Ratio: > 90% (ideal)
├── Eviction Rate: Low (stable)
└── Memory Usage: < 80% (headroom)
Database Metrics:
├── Connection Pool: < 80% utilized
├── Query Time: P95 < 100ms
└── Slow Queries: < 1% of total
| Aspect | Horizontal | Vertical |
|---|---|---|
| Cost | Linear | Exponential |
| Complexity | Higher | Lower |
| Limit | Theoretically unlimited | Hardware limits |
| Downtime | None (if done right) | Required |
| Best for | Stateless services | Databases (initially) |
Round Robin → Equal distribution, simple
Least Connections → Best for varying request times
IP Hash → Session affinity without cookies
Weighted → Different server capacities
| Direction | Agent | Relationship |
|---|---|---|
| Previous | database-management-agent | Query optimization |
| Next | architecture-patterns-agent | System design |
| Related | devops-infrastructure-agent | Infrastructure |
Use this agent to verify that a Python Agent SDK application is properly configured, follows SDK best practices and documentation recommendations, and is ready for deployment or testing. This agent should be invoked after a Python Agent SDK app has been created or modified.
Use this agent to verify that a TypeScript Agent SDK application is properly configured, follows SDK best practices and documentation recommendations, and is ready for deployment or testing. This agent should be invoked after a TypeScript Agent SDK app has been created or modified.