The ruleset I desire is (no AUTH requried):
READ:
* Allow whitelisted people to read everything
* Allow everybody to read events by whitelisted people
* Allow everybody to read all 10002 events
* Deny the rest
WRITE:
* Allow whitelisted people to write anything
* Allow everybody to write events where a whitelisted person is tagged [they won't be able to read them back, and that is very important]
* Allow everybody to write any 10002 event
* Deny the rest
I started work on a relay that uses similar ideas to yours but it is very early days. Events are appended to a mmapped file where readers are not blocked during writes (except during resize). Indices use concurrent lock-free kv system optimized for SSDs (rust package "sled") whose interface is like a BTree map between two binary blobs. I'm keying them with things like (pubkey,created_at) pairs so that I can handle since/until quickly. The value is just the offset in the mmapped events file. I'm using a form of serialization (called "speedy") that (at least in rust) performs faster than flatmaps (that may not count when switching languages). Incoming events go through slower processing to canonicalize their encoding and validate their ID and signature. Outgoing reads should be pretty close to as-fast-as-possible. All asynchronous to keep all the cores busy whenever there is work to be done.