

Ask HN: How to deploy a [Ruby on Rails] site in a scalable way? - tsycho

I have been working on my [first] startup for a month now, and while it's probably atleast one more month away from an alpha release, I want to know how to deploy it the right way. The site will have an initial high amount of load (network + CPU) for a new user, so I am thinking of having a separate server/queue for this initial process, so that it doesn't slow down the site for existing users.<p>Based on my research so far, I am currently leaning towards nginx + haproxy + unicorn/thin + memcached + mysql, and deploying on Linode. However, I have no prior experience in any of the above; hence I am hoping to tap the HN community's experience.<p>- Does the above architecture seem reasonable? Any suggestions/articles/books that you would recommend?<p>- Is Linode a good choice? Heroku/EY seem too expensive for me (atleast until I have enough revenue), but am I missing some other better option? MediaTemple?<p>- Any good suggestions on the load balancing architecture? I am still reading up on this.<p>- Is it better have 2 separate Rails server instances on 2 separate linodes, or running 1 instance on a linode of twice capacity (in terms of RAM/storage/bandwidth)? How many Linodes should I start with?<p>- Which Linux distribution should I choose (Linode offers 8 different ones - http://www.linode.com/faq.cfm)? Are there any relative [dis]advantages w.r.t. a Rails stack?<p>I apologize if any of my questions are stupid or contradictory; please attribute it to my inexperience.
======
malyk
If you are doing this by yourself with no system administration expertise then
do yourself a huge favor and go with something like Heroku or EY. Note that EY
will mean you have to do some sys-admin stuff yourself.

I only have experience with Heroku, but the costs for a new service aren't
going to be very high unless you have a lot of data.

For $15 a month you get up to 20 gigs of database on a postgres database.

2 dynos which will handle a ton of users cost $36 a month.

1 worker will also cost $36 a month if it's running constantly. There are a
handful of worker scalers out there to dynamically allocate a worker when it's
needed and turn it off when it's not.

So for starting up you're looking at 36+36+15= $87 a month (really less than
that since your worker won't be running 24/7).

Compare with the cheapest linode plan at $20 a month ($40 if you use 2
machines), plus all the time and hassle dealing with sys-admin stuff and the
time it takes away from your product.

~~~
tsycho
Thanks. If Heroku will cost me ~$100/month, I can definitely afford it. I just
got scared by reading articles where Heroku costs reached 1000s when there was
a usage spike.

~~~
malyk
The thing is you scale to meet demand. But unless you have a truly amazing
product then you don't have to worry about that right away. Sure, you may
scale up to 4 dynos to handle a techcrunch mention (or something like that),
at $0.20 an hour. But you don't have to keep using that many dynos after the
initial traffic spike. So you just scale them back after 2-6 hours and you pay
an extra $1-2 a month for those spikes.

Now, if you make it big and have to employ 25 dynos 24/7 then you are getting
into the territory of needing your own infrastructure. But that is probably a
long ways off and you'll be hiring people who know that stuff by then.

Google around for some performance comparisons of heroku, but I think that I
saw a something where you could handle 5000 or so concurrent users with
acceptable response times (i.e. not hitting the backlog too deep errors from
heroku), with just 2 dynos. Don't quote me on that, but it's what I remember.

If you go to heroku's pricing page you can play with the number of dynos and
workers all you want to see possible costs.

One other thing to remember is that if you have periods with no traffic (say
overnight at launch), then you can scale down to 1 dyno and your app will
still be available but it won't cost you a thing. So really that $87 is the
highest possible for a 2 dyno/1 worker deploy. You could save a lot of money
by scaling back to the free 1 dyno during periods of inactivity.

------
xentronium
FWIW:

MediaTemple is a reasonable choice. They give you quite a lot of cpu time on
VE servers. I say you spend 30 bucks and try the cheapest option. Never tried
linode/heroku though.

I found performance of thin in multithreading mode (with appropriate rails
settings) quite promising and having low memory footprint. No need to load
balance on a single instance since it handles everything cluster would (NB:
1.9+ ruby only). As far as I understand, the best way to load-balance is to
give one task per server at a time and keep other tasks in waiting queue.

Linux distribution are a matter of taste imho. I always go with ubuntu since
it's easier to set up.

------
spooneybarger
I would ask yourself this question about expensive. If you don't have much
experience with this, is the money that Heroku/EY would cost you really that
expensive when you consider the time you will spend learning how to scale your
application on your own and the possible service problems you might experience
while you learn. Cliches exist for a reason and 'you only get one chance to
make a first impression' is completely true. If I go to check out your site
and it is slow or down, I won't be coming back. Most people I know are the
same way.

~~~
tsycho
I have asked myself this question.

However I do not want to give up without making a sincere attempt first. I
intend to set up my own infrastructure, load test it, and see if it's working
well enough. If I fail to do so, Heroku/EY remains the backup solution.

