How to Scale a Mobile App?

What is a good initial architecture for a social web app on AWS that can scale over time?

  • Assume the following characteristics: a "normal use" web app (i.e. not "real time", maybe traffic spikes from PR but not for normal use), probably an "average" read vs. write ratio for a social app, some heavy back-end processing/algorithms to prepare data for the site, and LAMP stack.  I realize this is a broad question.

  • Answer:

    The simplest setup consists of a Small EC2 instance and a small RDS instance. (Small server and small database.) Than, the most important thing to do is to move out the static content to S3/CloudFront. That way you free up your web server to do serious work, and not serve out files. If this gets a bit slow you want to move to a Medium instance. This can handle 2 to 4 times the traffic of a Small instance, in most cases. The moment you have to make this step start looking into Elastic Load Balancers. But make sure you know how to scale a database 'cluster' too. Look at memcached, for examples. If you think you understand how your app behaves implement Auto Scaling. With this service you can run in 'idle state' with the minimum of EC2 instances, and scale out when your traffic demands. These techniques can help you scale considerably. If you need more you need to take drastic measures, you need to start decoupling your system. For that services like SQS, SNS and SimpleDB are ideal. But you can use those services right from the start as well, of course.

Jurg van Vliet at Quora Visit the source

Was this solution helpful to you?

Other answers

Here is a broad answer: I wrote about the architecture about a Rails site I've been working on earlier - here is an extract. It's pretty similar for any architecture in that you'd want to add Varnish for aggressive caching and memcached would do as well. You'd want to use a micro instance or a small instance for load balancing ( Nginx or HAProxy would do the trick). For instant spawning of instances and defining your environment, use something like Chef or Puppet. Extract (from I always wanted to have an excuse to use Amazon Elastic Cloud Computing for my projects. I finally got the perfect chance when they announced free Micro Instances for new customers. The offer is pretty reasonable and I jumped the gun on it. EC2 is fairly easy to set up. You sign up with your credit card, get the certificate and keys and spawn up some Virtual Machines. Something I didn't know until I played with EC2 was that all instances are very much "temporary" as in - think Live CD of Ubuntu with lots of virtual disk space. But, this can be solved by using Amazon's Elastic Block Storage which persists your VM sessions and lets you take snapshots a la VMWare, Parallels or Hyper-V style. You can find virtual machines or Amazon Machine Images (AMI for short) made by the community for your perusal. I tried about a dozen different instances with various things already installed in it such as Rails 3 stack with Nginx and the sort. I ended up going with a Nginx and Thin server setup. I run 3 Thin servers and Nginx as the reverse proxy. I have MySQL for database, Sphinx and ThinkingSphinx for search backend. The rest of the miscellaneous details are below. Of course, the thing I had the most trouble was deploying. As I mentioned before, Heroku is freakishly the best way to deploy light weight apps. Stick with it if your needs are basic. For EC2, I tried about half a dozen different ideas and decided that Capistrano is still the best option. There are some gems out there that can make deployment easier. One such one is Rubber. It claims it can spawn multiple instances and setup master/slave read for MySQL, and more. It just didn't workout for me mainly because I wanted to first go through the pain of setting up everything myself and besides I couldn't get Rubber to play along with EC2's somewhat old gem; the EC2 gem didn't have micro instances as an option and I resorted to the decent thing to do - edit the gem to make it work. It still didn't fix the problems. So, another problem is setting up your AMI for the stack you want. Having played around with Hyper-V, VMWare and Parallels, I expected this to be a pain. But of course, it's different on the cloud - things can go poof or you want a new instance for your app server or web server. One option is to make your own AMIs, but a classier way is to use Chef. Chef is an amazing piece of tool where you can describe your entire infrastructure in ruby and it does the magic for you. I used a thing called Maestro (a Chef plugin) for easy setup. It was working sometimes, but again the micro instance problem with EC2 gem didn't help. But, honestly for my little learning experience, I was happy finding the right tools for the right job at the right time. Passenger Phusion + Nginx (on test server) is pretty sweet. The setup again is very easy as expected and some things to look for are Gzip compression of all your static resources and setting cache expiry for a longer time so as to minimize calls to your assets. Besides compression, you should minify all your javascript files (I hear Sprockets is pretty good) and use Google's hosting of jQuery library for speedy loading (though reliable, you should add a fallback local version). Other resources: https://github.com/blog/517-unicorn - great writeup on scalable architecture Lots of great architecture stuff here - http://highscalability.com/

Sam Jp

I will add the use of a Cloud Management to the list of softwares you can use to create a LAMP stack from scratch and scale it proportionally to the read traffic. My company Scalr (http://www.scalr.net) offers pre-configured mixed role for EC2 with a MySQL DB, an Apache server and a Load Balancer at the top. You can use these for development and scale up during production. Automatically! We wrote a special blog post highlighting this special feature: http://scalr.net/blog/feature/2-1-feature-highlight-scale-from-one-to-many-servers/.

Julien Rialan

Not sure if you're looking for an architecture diagram or just advice on which services to consider, so I'll take the latter.  Use EC2 for your servers with auto scaling, EBS and S3 for storage, RDS for general database stuff and SimpleDB for anything you think might eventually scale to crush your database.  Of course, since you've given us almost no detail about your usage...  and there are lots of other things that AWS can and should be doing for you, so YMMV.

Scott Sanchez

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.