How we optimized our server stack for scale – Part 1

Posted on

Over the last 1 year, we’ve seen strong growth in traffic and usage of our platform. Akosha has a three way complaints handling platform – the system is used internally by 30+ employees to review, respond and follow up on the tickets, externally by more than 40,000 customers whose tickets are live at any given point and over 100+ brands which log-on daily to answer the complaints. This kind of growth forced us to look at latest technologies and adopt them for our purposes. As a startup, we chose to stay with open source technologies not just because they are free but also because we strongly believe that open source technologies are good enough for us to do what we want. So here is a quick glimpse of how we went about optimizing our tech: Dumping Apache for nginx The first thing we did was to dump Apache web server to use the shiny nginx. Here is why: nginx is recognized as a good server for sites that need fast, efficient reverse proxies (we use tomcat as a backend server) or fast, efficient serving of static content (lots and lots of pages which don’t change much over time). It is also uses a lot less memory than Apache. Chris Lea puts it best: “Apache is like Microsoft Word, it has a million options but you only need six. Nginx does those six things, and it does five of them 50 times faster than Apache”. Another difference is that Apache is a process-based server, while nginx is an event-based web server. I won’t go deeper into the discussion on process-based vs event-based (Google is your best friend). But the main reason for us to use nginx was its inbuilt ability to cache static and dynamic content (varnish is also a very good option). This was very important for us because we have too many pages and all of them are data driven, which in turn means it will always take more time than static pages. Nginx + caching = more than 50% reduction in load time Nginx made it very easy for us to make some rules to cache pages for users who are not logged in. Result: a page which used to take 2.5 secs for Google to crawl now gets crawled in less than 0.4 secs.

Google Webmaster Tools | Crawl Stats | http//www.akosha.com
Google Webmaster Tools | Crawl Stats | http//www.akosha.com

All the pages for logged-in users are reverse proxied to tomcat and nothing is cached other than js,css images etc. which are also cached at the browser end These lines below does the magic of telling the browser to cache the file types for 30 days: if ($request_uri ~* ".(jpg|jpeg|gif|gz|zip|flv|rar|wmv|avi|css|swf|png|htc|ico|mpeg|mpg|txt|mp3|mov|js)(\?v=[0-9.]+)?$") { expires 30d; access_log off; break; } Technologies we use

Akosha technology stack
Akosha technology stack

Front end: Twitter Bootstrap combined with LessCSS works quite well for us. Rest of the stack is standard – jQuery, Javascript, HTML. Maybe I’ll write a separate post about how we have optimized the front end. Our Java stack (Struts2, OGNL, Spring, Hibernate) talks to MySQL and Mongo with memcache in between to cache frequently used data to make it even faster. We use Node.js + FAYE for real time push notifications to client browser on our homepage. RabbitMQ is used to queue all email and SMS requests. We use Sendgrid as our email service provider. We use Amazon s3 to store our meta files like uploaded files from customers etc. This is an introductory post talking about the different technologies we use and why we chose them over comparable technologies. I’ll talk about the challenges we faced in each of these over a series of posts. Vishal Pal Chaudhary is the CTO at Akosha. Previously, he had co-founded Topchalks.com, a technology based education startup backed by DFJ Ventures.

Leave a Reply

Your email address will not be published. Required fields are marked *