CacheNet models cache nodes, clients, a load balancer and an origin database as independent agents on a discrete-event clock. Run it and watch the hit ratio move — including the moment a node dies and the keyspace re-warms without it.
Python engine
FastAPI
WebSocket telemetry
Next.js
Model topology
RunningNothing in the model is scheduled by hand. This is the sequence the engine produces for a single key when a write lands just before a read.
0 ms
Client writes
A client agent puts a new value for one key onto the queue.
5 ms
Origin accepts
The database records the write and issues invalidations.
10 ms
Nodes invalidate
Every cache node holding that key drops its copy.
15 ms
Client reads
A read for the same key reaches the load balancer.
20 ms
Cache miss
The routed node no longer holds the key and asks the origin.
30 ms
Client answered
The value returns, and the next read on that key will hit.
Request in flight
Served from cache
Fell through to origin
Node failure
— the only four colours in the interface.
Each agent only knows its own state and the messages it receives. Everything you see on the dashboard — thundering herds, cascading misses, recovery — comes out of those local rules.
load_balancer
Routes each request to a node by key hash, keeping affinity stable.
service_node
Holds an LRU cache, answers reads, honours invalidation and TTL.
client
Generates the read and write traffic that drives the model.
database
The source of truth. Serves misses and invalidates on write.
network
Applies latency and loss to every message between agents.
chaos_monkey
Kills or degrades nodes at random to test what the cluster does next.
observer
Samples hits, misses and latency, and streams them to this interface.
heapq
O(log n) scheduling, ties broken by event id.
OrderedDict
O(1) LRU get, set and eviction per node.
WebSocket
Telemetry sampled every 20 ms of model time.