5 ms·
To me, that just sounds like it forces you to do the Right Thing from the beginning. Eventually, you will need to shard your data in some way†. If you're alrea
by derefr 11y ago
To me, that just sounds like it forces you to do the Right Thing from the beginning. Eventually, you will need to shard your data in some way†.
If you're already locked into a "global queries against tables containing Everyone's Stuff" data model, you end up doing this through Stupid Database Tricks like "see-other" redirection or silent persistent-hash load-balancing (with constant ops-heavy rebalancing as you grow.)
If you think about sharding from the beginning, though, you end up just dividing your data into little naturally-atomic "worlds." Like sharding email [headers, not bodies] by user, or sharding StackOverflow posts by community.
If you don't think you'll ever scale to the point where you'll be forced to make those calls, just pick a different database. (But then, if you don't think you'll ever reach that scale, then literally any database will do.)
---
† Unless you're EVE Online. They could probably write a really good whitepaper about how they've scaled their single-node MSSQL database so far. I presume they're mostly following the same patterns you would when running e.g. Oracle on big iron; but—according to most sources—they're just using some heavily-loaded commodity hardware with no fancy IO offloading et al. No idea how they do it.
- biokoda 11y agoWell put.
- lobster_johnson 11y agoAbsolutely. Keep in mind that ActorDB actually requires that you supply the sharding key yourself whenever you do a query. It's not like, say, Elasticsearch, which shards both reads and writes transparently. Many apps do require large queries that span many "partitions": For example, listing all of a StackOverflow member's contributions across all communities, sorted by time. With ActorDB, you would have to plan for this by denormalizing a bit (biokoda might correct me here): Each community would be an actor with a table of QA items, and each user would also have an actor containing a table listing their own QA items for all communities. Since ActorDB apparently has transactions, you can maintain this duplicate data atomically, though you can't maintain foreign-key constraints across actors.
- derefr 11y agoI work with CouchDB, and it sounds similar: many queries end up being map-reduce functions run across many CouchDB "databases" (partitions) on the same node/cluster. One of the nice things about this approach, from my CouchDB experience, is that each DB/partition has its own permissions (fully extensible through design-documents shoved into that DB), so instead of needing to carefully write your business layer to ensure that users can only ever query their own data out of a table, you just do all your work for a particular user in a table that only contains stuff that user has a right to access to begin with. It's a lot like working with S3 buckets, now that I think about it. Buckets containing tables, rather than buckets containing objects.
- biokoda 11y agoYou can actually get very far by not sharding. But it forces you to eventually throw out everything that makes relational databases awesome and turn it into a glorified KV store.
- rodgerd 11y ago> they're just using some heavily-loaded commodity hardware with no fancy IO offloading et al. Aren't they backed by RAMSANs?
- calpaterson 11y agoNo, most businesses could run their datasets off normal databases. This becomes more true every year as stock hardware gets bigger ram and disks. There are plenty of businesses running of single-node SQL databases. Not Google's scale, fine, but the same scale as the bottom 99% of businesses. For the record, StackOverflow (your example) is run off a single MS-SQL cluster. It's not even that heavily loaded apparently: http://highscalability.com/blog/2014/7/21/stackoverflow-update-560m-pageviews-a-month-25-servers-and-i.html http://highscalability.com/blog/2014/7/21/stackoverflow-upda...
- derefr 11y agoYes, that's what I said: for most businesses (that aren't trying to scale to infinity the way that VC startups talk about), literally any database will do. Even single-node SQLite will do, because there won't be enough contention for its locking to ever matter.
- catnaroek 11y agoPlease excuse my ignorance - how do I enforce nontrivial system-wide invariants with lots of little databases rather than a single consolidated one? The invariants I care about are: (0) Referential integrity. If the table `Foo` has a `FOREIGN KEY (BarID) REFERENCES Bar (BarID)`, then no row in `Foo` must be seen as having a `BarID` whose value can't be found in the table `Bar`. (1) Linearizability. There must exist a total order on the entire transaction history of a database, such that, starting from the empty database, and executing the transactions nonconcurrently in the given total order, the result is the current state of the database. (NOTE: The transaction history need not be physically stored anywhere. So this invariant can't be “tested” - it has to be proven to hold.) These guarantees are so basic, so fundamental in my everyday use of RDBMSs, that I need to be convinced that they hold.
- biokoda 11y agoBy finding the natural sharding factor. If you have one, which very often you do. Three completely different examples: - Are you running a mail server? Every user is an actor (i.e. an sqlite instance). - Are you running a backend for a dropbox/evernote/messaging type app? Every user is an actor. - Do you have a distributed filesystem? Use the KV mode and shard on file hash. - Do you need scalable counters? Use KV mode again, split every counter into 10 (or 100) and increment/decrement on those.
- catnaroek 11y agoAgain, please excuse my ignorance - what is the definition of “natural sharding factor”, and how would I compute it for, say, an ERP system?
- biokoda 11y agoI have no experience in developing in ERP systems. I do have experience on being at the end of a very poorly working one. These systems seem (from my outside view) to have a tendency to become giant monoliths. So when developing you must fight against increasing monolithic complexity. Using something like ActorDB can be somewhat of a beneficial constraint. It forces you to maintain a clean design. I would force sales, marketing, shipping, product planning (taking from wikipedia here..), to be their own separate actors with their own schemas. Then if possible shard within those types. So if something is customer service, have an actor per customer and have all his data there. If you're developing multiple products, every product has an actor.