133 points · by rjim86 · 14y ago · 66 comments
You can't really avoid having a patchwork of technology, because it's a patchwork of problems. Instead, there're a bunch of tools at your disposal, a few "best practices" which are highly contextual, and you have to use your judgment and knowledge of the problem domain to put them together.
For most websites is not THAT different.
Actually, most have pretty similar needs, and you can sum those up in 3-5 different website architectural styles anyway.
There is far more duplication of work and ad-hoc solutions to the SAME problems than are "heavily different" needs.
So they can pick and match from the "scalable read only" commodity system, the scalable "message routing system" etc.
But with SSD, RAM becoming a commodity, ( both prices has been dropping shapely ) I/O are much easier to deal with.
And with every release of PostgreSQL / MySQL, Easier Database Replication and more common practice of scaling we are much much better at it then say 2 - 3 years ago.
I hope they introduced some NoSQL sweetness by now.
They turned their RDBMS into a NoSQL database that's still slowed-down by all the relational machinery.
Though I'm sure this was an informed choice at the time, I seriously hope nobody finds this advice actionable anymore. Use Cassandra. (Or your NoSQL DB of choice)
Source: ive hacked at the codebase to produce arxaliv
I remember when the Bigtable paper was released. It was very early in my career and I remember it sounding so alien to me. Sure, i had Memcached in my stack, but no SQL? It seemed like something they had to trade off to be able to build the kind of services they offer. I felt the same way after reading Dynamo.
Sure, I thought a lot about data design. I thought about usage patterns to inform how we denormalize. And I grew into using, eg, Gearman, to pre-compute dozens of tables every night. I evolved, a bit.
But a few years ago, a little before this OP was written, I had a great experience with some Facebook engineers and had an a-ha moment that has made me a much better software engineer. Basically, I realized that I needed to let my data be itself. If I have inherintly relational data, then it should be in a relational database. But I've built EAVs, queues, heaps, lists, all of these on top of MySQL and Postgres. Let that data be itself.
We have more options now than ever before. K/V stores, Column stores, etc. I use a lot of Cassandra. A lot of Redis. Some Mongo. And a put a lot more in flat files than I ever thought I would.
I know a lot of people that are smarter than me left the womb knowing these things. But for me it was transformational and has made me much happier. I realized how much energy I wasted fighting my own tools.
Postgres has good support for being used as a key/value store. http://blog.reddit.com/2012/01/january-2012-state-of-servers... indicates they're still using Postgres for the main backend, and Cassandra next to it as both cache (it replaced memcached back in 2010) and to store data for some features (moderation log and flairs)
http://blog.reddit.com/2012/01/january-2012-state-of-servers...
Go with Redis for storing session data.
Going statless wherever possible almost always wins. (And I only say "almost" because I'm not smart enough to know if it really always wins. But for me, it has)
What do you mean by data you are caching in a session? Session is for maintaining state viz. logged in or not, language preference etc.
How is storing in Redis(or any other data store) any different from storing in Memcache?
> Going statless wherever possible almost always wins.
Using sessions with a data store which can be accessed from multiple machines(no files or in-memory stores) is stateless. The simplest implementation will have a signed cookie with a session id. Your application will have a hook to load the user session from the backing data store before processing the request.
Memcached is a cache, not a store. Memcached happily removes keys when it feels so
Please see this post where memcached author recommends not to store sessions in memcached: http://dormando.livejournal.com/495593.html
This isn't babble -- it's honestly a pretty common technique. If your site sees millions of users, storing a session for visitors that aren't logged in is prohibitive and unnecessary. You can store UI customizations and basic memoization in a client-side cookie if you need to.
If you're building something small or basic, then you probably won't have multiple webservers and you can use fast in-memory sessions without concern. This only applies once you need to worry about scale.
Well yeah it's from early 2010, it's been 2 years. In January (2012)'s "state of the servers" post, the reddit blog noted traffic was 2 billion pageviews per month in December 2011, up from 870m or so in December 2010.
The point is that there are solutions offering equivalent speed without that barrier, so why select a technology that has limitations?
But even anything approaching even half a MB of session data I would take as an architectural failure, and work to fix it, instead of letting it dictate what tools I use (ie. redis vs memcached).
>The point is that there are solutions offering equivalent speed without that barrier, so why select a technology that has limitations?
Because all decisions have tradeoffs and it more wise to depend on your particular use case to choose than to depend on a scenario (> 1MB session data) that can only happen with a seriously fucked up application design.
var queue = [];
// request handling
module.exports = function(request, response) {
queue.push("bla");
response.end("bye");
};
// out-of-request work
setInterval(function() {
// do something with your queue either locally
// or moving it to an external job queue that can
// leverage the same script on a different thread
}, 1000);In my case I periodically query mongodb for new or updated data since the last time to be stored locally, push batches of data into redis, track and save load information etc all without any negative repercussions.
Either way, no need to hate on the traffic figures of what everyone knows is a very large website.
[0] according to http://blog.reddit.com/2012/01/january-2012-state-of-servers..., December 2010 saw 829 million page views
http://blog.reddit.com/2012/08/potus-iama-stats.html
> At the peak of the IAMA reddit was receiving over 100,000 pageviews per minute.
> In preparation for the IAMA, we initially added 30 dedicated servers (20%~ increase) just for the comment thread. This turned out not to be enough, so we added another 30 dedicated servers to the mix. At peak, we were transferring 48 MB per second of reddit to the internet. This much traffic overwhelmed our load balancers which caused a lot of the slowness you probably experienced on reddit.