Adapter calls to external retailer systems.
Adapter latency spikes are usually caused by upstream throttling, slow network paths, or lack of connection pooling. This playbook focuses on instrumentation and performance fixes.
- P95 adapter latency exceeds SLA
- Identify slow endpoints and payload sizes.
- Check network path and DNS resolution.
- Confirm rate limit or throttling signals.
- Add caching for hot queries.
- Reduce payload size or request frequency.
- Parallelize independent calls.
- Reuse HTTP sessions with pooling.
- Set timeouts and circuit breakers.
- Add request-level latency logging.
- Reuse HTTP sessions with a connection pool.
- Cache hot queries in Redis.
import aiohttp
class PooledAdapter(BaseAdapter):
def __init__(self, api_url: str):
super().__init__()
self.api_url = api_url
self.session = aiohttp.ClientSession(
connector=aiohttp.TCPConnector(limit=100),
timeout=aiohttp.ClientTimeout(total=5),
)
async def _fetch_impl(self, query: dict):
async with self.session.get(f"{self.api_url}/item/{query['id']}") as resp:
resp.raise_for_status()
return await resp.json()async def fetch_with_cache(sku: str):
cache_key = f"inv:{sku}"
cached = await hot_memory.get(cache_key)
if cached:
return cached
value = await adapter.fetch({"sku": sku})
await hot_memory.set(cache_key, value, ttl=300)
return valueflowchart TD
A[Latency spike] --> B[Measure adapter latency]
B --> C{Network or upstream?}
C -->|Upstream slow| D[Reduce payload + rate]
C -->|Network| E[Enable pooling + timeouts]
D --> F[Cache hot paths]
E --> F
If latency persists, open a ticket with the upstream provider.