I’ve always believed that the best solution is the simplest one. They tend to be more fool-proof, reliable, and easier to maintain in the long run.
That said, I had a hard time believing my own eyes when I found what might be the holy grail of High Availability (HA) and High Performance Computing (HPC) : easy & transparent (no apps recode) sharding, with HSCALE.
A bit about sharding : also known as “shared nothing architecture”, this will enable almost infinite scalability to any system. Google, Facebook, Flickr, MySpace – you name any high-traffic website, and there’s very good chance that they already implemented it in one way or another. Whenever they need more performance, they only need to throw another box into the system, and that’s it. Instant performance gain.
However, there’s a significant drawback – to most, sharding means a total rewrite of your application.
I’ve been providing consultation services to several high-traffic websites. They’re doing pretty well now, but some are about to go to the next level. Where their current standard 4 tier architecture; edge server – webserver – apps server – database, no longer suffices, and will need to scale up (bigger server), or scale out (more servers).
Most, however, could not rewrite their apps for sharding for various reasons; number of resources needed, development time, potential reliability issues, and so on.
Let’s back up a bit (this can be very helpful; sometimes we’re to busy charging forward, as fast as we can – thus missing all the hints we encountered along the way).
If we examine this infrastructure, almost all aspects of it are already easily scalable. Edge servers: check, you can throw another box and instant performance gain. Webserver & Apps server: checked as well, especially with PHP where it already implements the shared-nothing architecture. We can even load-balance them using software and have it outperform and out-feature the hardware load-balancers .
So that leaves the database as the bottleneck.
For the database, my requirements are simple (cough) :
- Scale out, not up : There’s a limit to how big a server can be. Several high-traffic websites (YouTube, MySpace) had chosen this path and they’ve experienced the pain when they hit the dead-end – no more server bigger than what they already have. So it definitely will have to be a scale-out (more boxes) solution.
- Transparent : No application recode.
- Easy to maintain : I want a system that doesn’t need constant babysitting. I (we all) have better things to do with my (our) time.
- Works for MySQL : it’s the most used database for web-apps, currently.
- Affordable : at least, provides several pricing schemes. Not just one. We all have different needs and budgets.
Yeah, I’m picky. And that caused me serious headache – for weeks I was not able to find anything.
Several that I looked into :
- MySQL cluster : NDB = memory/RAM-only tables? Full backup/restore everytime we add new server? No thanks.
- MySQL replication : I looked into single/multiple master – multiple slaves setup. Doesn’t like it (1) I have systems which will need scalability for write ops as well (2) for read ops, caching (especially memcache) can provide better performance gain with less headache (3) It’s Asynchronous – meaning: the user edited his profile, clicked save; and lo, the old profile is still there (because the update hasn’t reached the slaves yet) (4) multiple master scheme seems only safe for up to 2 masters; I don’t fully understand the risks with more than 2 masters (not enough case studies).
- MySQL partition : Good idea (although doesn’t do vertical / column-level partitioning yet, but that’s ok ). There are limits, but it’s not a showstopper for most. However, it doesn’t scale-out.
- Various MySQL load-balancers, replication, HA solutions : Pick any / several of these : unproven, costs an arm and a leg, proprietary, needlessly complex, need loads of maintenance work, etc.
Here’s the beauty of its simplicity : It’s just a plugin for MySQL-Proxy 🙂
MySQL-Proxy is a high-performance proxying daemon for (guess what) MySQL, created by Jan Knesche – also well-known for Lighttpd: one of the fastest webserver on Earth. Then Peter Romianowski decided that he’ll build his sharding-proxy upon this great foundation.
So we have HSCALE.
Amazing, this solution to high-performance database (HSCALE) is similar to high-performance Apps server (HAproxy) : through proxying 🙂
Configuration is dead simple. Ability to spread queries to multiple backend servers (with some minor limitations, but it’s being actively worked on) – transparent to the application. Version 0.3 will enable us to run multiple instances of HSCALE (to avoid it becoming the bottleneck). And it’s free (do remember to contribute back if your website becomes successful because of it). With MySQL-Proxy’s scripting capability, it provides an easy & clean way to extend it to fulfill your own requirements. Etc.
Currently not many people knows about HSCALE’s existence, so I’m writing this article to let more people know about it.
At the moment HSCALE’s is already making great progress. I’m sure it’ll become better at much faster rate if more people know that it existed. So here it is.
And kudos to Peter Romianowski & Jan Knesche for their software. Here’s cheering for great future of both MySQL-Proxy & HSCALE.
A small FAQ for now, no doubt the list will be bigger as I (and you) found out more about this :
- Q: So, come again, how does HSCALE works?
A: First you define the partitioning scheme on HSCALE’s config file. Then it’s all automatic from there, HSCALE will partition / regroup the rows – not your application.
- Q: What’s the difference then with MySQL’s partition feature ?
A: You can spread HSCALE’s partitions to multiple databases (meaning: multiple backend servers), while MySQL’s only works on a single database.
OK, my head still hurts from doing marathon reading of so much documentations on this topic (transparent sharding) ! Chances are great that there are errors in this article. If you do find them, please leave a comment so I can fix it. Thanks !
In the meantime, shall we play with HSCALE in the Sandbox? Have fun !
 HAproxy seems indeed is the leader of the pack (apps/web server high availability + load balancers) at the moment. It can load-balance 20 Gbps with the CPU 85% idle, have loads of great features, and secure. Even 37signals.com swears by it (and so does several Forbes 500 companies).
 MySpace found out that vertical-partitioning does not scale.