TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Skipping the boring parts of building a database using FoundationDB

75 pointsby ovaistariqover 2 years ago

5 comments

endisneighover 2 years ago
It&#x27;s a shame that FoundationDB went closed source when it did, since that was the key period (imo) for database exploration - the early 2010s. If it would&#x27;ve been more popularized then I imagine most people would be using it now.<p>The nice thing about FDB is that after 3 plus nodes, you can simply add nodes using your cloud provider of choice and it scales pretty nicely while still giving your high availability and fault tolerance.<p>It&#x27;s pretty funny to me though to see this - I&#x27;ve been spending a few days building a simple database on top of FDB that supports indexes, secondary indexes and schema migrations backed by json-schema (very, very similar to this, totally independently!)<p>To get into a little bit, it&#x27;s not super difficult if you use FDB. FDB is a very bare key value store. It&#x27;s incredibly low level. You don&#x27;t even get a notion of collections. You have to implement everything yourself. what it does give you, however, is a giant hash map that will guarantee that items are in sorted order.<p>so to build what I was describing it&#x27;s easy:<p>a collection can be a tuple to map:<p><pre><code> (your-app, your-collection, _id, your-model-id-number) =&gt; json </code></pre> e.g.<p><pre><code> (hn-app, users, _id, 1) =&gt; { _id: 1, username: endisneigh } (hn-app, users, _id, 2) =&gt; { _id: 1, username: reader } </code></pre> an index can be something like:<p><pre><code> (your-app, your-collection, your-field-to-index, index-value, _id, your-model-id-number) =&gt; json </code></pre> e.g.<p><pre><code> (hn-app, users, username, endisneigh _id, 1) =&gt; { _id: 1, username: endisneigh } (hn-app, users, username, reader, _id, 1) =&gt; { _id: 1, username: reader} </code></pre> Because FDB gives you transactions, you maintain the index by populating the keys according to the pattern above on your create* and update* operations.<p>To do something like a schema migration, FDB gives you a get_range operation that you can use to find all keys that have a prefix. So what you&#x27;d do is store a value indicating that you&#x27;re doing a migration into the database, iterate through the keys in a batch (so it&#x27;s all a single transaction), update the value in the db saying what the last key you&#x27;ve migrated is, and continue until you&#x27;ve done all of the keys.<p>A lot of stuff is pretty trivial once you assume the underlying semantics are solved. I&#x27;ve seen some interesting projects involving things like using FDB as a virtual file system for SQLite, but the problem with that is FDBs primitives are actually flexible, and so there are optimizations you can make if you built it using those primitives from the beginning, as opposed to using FDB as simple a key value store without taking advantage of the transactions.<p>-------<p>On another note, one idea I&#x27;ve had (feel free to steal) is to reimplement IndexedDB using FoundationDB. IndexedDB is also a key value store which supports transactions, like FDB. Obviously IDB is not networked.<p>The idea is that if you can semantically map IDB with FDB, then you could use FDB as a store for IDB (scoped to the user, of course). And then any app that uses IDB for its storage (like an offline app) could use FDB as the backing without having to use a different set of data structures to actually represent the storage.
评论 #32932591 未加载
评论 #32932642 未加载
评论 #32934518 未加载
评论 #32936297 未加载
评论 #32933134 未加载
Scarbuttover 2 years ago
Is there a &#x27;limits&#x27; doc somewhere? how many objects can an array hold? what is the depth limit for nested data?
评论 #32933977 未加载
评论 #32934905 未加载
asiejhfasdfhjover 2 years ago
Kudos! you guys tweaked the sales pitch in a single day!
评论 #32933985 未加载
ithrowover 2 years ago
Can typescript be limited to just creating the schema and then use javascript for the rest of your application?
评论 #32936104 未加载
ovaistariqover 2 years ago
Building distributed database systems correctly from the ground up is a notoriously hard problem. We have seen this firsthand building Docstore at Uber.<p>This is one of the most confusing aspects of the modern data infrastructure industry, why does every new system have to completely rebuild (not even reinvent!) the wheel? Vendors are spending so much time rebuilding existing solutions, they end up not solving the actual end users’ problems, although ostensibly that&#x27;s why they decided to create a new data platform in the first place!<p>In this post we talk about our approach to building Tigris - the open source developer data platform. We talk about why we chose to build on top of FoundationDB, one of the most reliable distributed KV store with an amazing correctness story. We also go into detail about our experience using it.
评论 #32932232 未加载