|
|
|
|
|
by Horos
100 days ago
|
|
Three real risks in your current approach before anything else. Shared references mutate silently — in JS, objects passed between your "tables" are aliases, not copies, so a mutation in one place propagates everywhere with no transaction and no rollback.
No atomicity — Node is single-threaded but async I/O means two callbacks can interleave writes on the same structure with no guarantee a multi-step update lands cleanly.
And everything disappears on crash — for socket/port/container state that's probably fine since it's observable from the system anyway, but you have no history. That said, you may not need to leave your stack at all. V8's native Map is already a key-value store — O(1) reads, no overhead, typed in TypeScript. Your "tables" are just Maps and cross-referencing is composite string keys: sockets.set(serverId:{serverId}:
serverId:{socketId}
, socketData).
No library, no dependency, no SQL. This covers your use case as described. If you want ACID transactions and persistence without SQL, look at lmdb-js — a Node binding on LMDB, the fastest embedded KV store in existence, zero-copy reads, used in production for 20 years. Your tables become named databases, your records are typed values, your cross-references are composite keys. Same mental model you're building, with 20 years of correctness guarantees underneath. What's the actual reason for building from scratch rather than using native Map for the in-memory case? |
|