Nostr relays, caches, and databases should all use the same storage interface so you can compose and replace them. You should be able to use a remote relay, SQLite, or in-memory cache interchangeably with the exact same interface.
Discussion
It’s still VERY early stages. But that is one of the concepts of my #nostr relay. You can currently use in memory, file system, or SQLite. On my radar to add Postgres and remote relays, and hopefully more. https://github.com/rrainn/nostr-relay
Totally
Maybe nostr protocol would be the right interface? Ofc it can be wrapped in get / set or publish / subscribe methods. https://github.com/nostr-protocol/nips/blob/master/01.md#communication-between-clients-and-relays