Prepare the stores
This guide prepares Redis, PostgreSQL, MySQL and MariaDB, and the HTTP services serving calls, before hooks write to them and serving reads them.
Before you start, know which stores your hooks write (their sinks and queues) and which ones your statements read (their sources). Hook writes land on the stores serving reads, at the pace records arrive. A replay after a long stop writes at the store's full speed, the stores serving reads included: size each store for that peak, not for the usual rate ( Limits ).
1. Redis that holds an index or a queue
An index, the latest values and a Redis queue are as durable as their store, and only a replay rebuilds them.
- Turn eviction off. Run Redis with
maxmemory-policy noeviction. An eviction policy, common on a cache, drops index members and queue entries without a trace. - Turn persistence on. A Redis without persistence (AOF or RDB snapshots) loses everything at a restart. With snapshots only, it loses the writes since the last one.
- Size its memory for the indexes'
RETENTION. How many members an index holds, and how to measure their bytes, is in Size Redis memory for an index .
redis-cli CONFIG GET maxmemory-policy # noeviction
redis-cli INFO persistence | grep -E 'aof_enabled|rdb_last_save_time' What a failover costs
A failover loses what was not replicated: writes acknowledged by the old primary after the hook committed its offsets are not read again. While the new primary is promoted, Redis answers READONLY or LOADING, and the hook retries without data errors ( Store-state answers ). To recover the lost writes, replay the topic from before the failover, within its retention ( Replay a topic ).
2. A database that holds a queue
Every queued reference is a row inserted, updated and deleted. In PostgreSQL, let autovacuum keep up with the queue's table, or tune it for that table, or the table and its index grow. When featuremeshd creates the queue's table is in Queues .
3. The databases serving reads
- Share one source per database. Create one
SOURCE_DB()per database and use it from every feature. featuremeshd pools its connections ( Database sources ). - Index the columns a call filters on. The columns in
BIND TOclauses and in the equalities ofRELATED(… ON …)becomeWHEREconditions in the SQL sent to the database. Index them, with the time column second when a window filters on it. The check at registration (UE/SERVING-NOT-A-KEY-LOOKUP) refuses a read without a key, but it does not read your database's catalog: indexes are yours to create. - Plan for bursts. Serving sends concurrent queries when many calls arrive at once. Watch the database's load and connection limits, and add read replicas or a cache when they are reached.
- Bound hot keys and set timeouts. A key with far more rows than the others, such as a merchant with millions of payments, makes every call on it slow. Bound what a call reads for it, and give each source a realistic
timeout( Timeouts ).
Check an index with the SQL the call sends. The shape of that query is in Where aggregations run :
EXPLAIN SELECT account_id, COUNT(*) FROM history_events
WHERE account_id = ANY('{1,2}'::BIGINT[]) AND event_ts > now() - INTERVAL '30 days'
GROUP BY account_id; -- an Index Scan on (account_id, event_ts), not a Seq Scan 4. The services serving calls
An HTTP source sends up to 32 requests at a time, with no retry of its own ( HTTP sources ).
- Set short timeouts. A slow service should fail fast, rather than hold the whole call. What a failed read returns is the statement's choice ( Errors and fallbacks ).
- Mind the service's rate limits. Bursts of calls become bursts of requests. Ask for a limit above your peak, or put a cache in front of the service.
Check the stores
- Redis:
maxmemory-policyisnoeviction, persistence is on, andused_memorystays undermaxmemorywith room for a replay. - PostgreSQL: the queue's table does not grow between drains (
pg_stat_user_tables.n_dead_tupfalls after each autovacuum). - The database queries serving sends use your indexes.
Common failures
- Index members or buckets missing without an error: Redis evicted them. Set
noeviction, then replay the topic. - Everything gone after a Redis restart: no persistence. Turn it on, then replay.
- Serving slow during a replay: hook writes compete with serving reads on the same store. Size the store for the replay's peak, or replay at a quiet time.
Related
- Size
RETENTION,EXPIREand memory : theRETENTIONand the memory these stores hold. - Deploy featuremeshd : credentials for the stores.