When you are building native or HTML5 mobile applications choosing the right platform for the supporting services is essential. The platform you choose must be flexible and scaleable enough to grow with your business as your app gains popularity. There are many cloud platform services that fill this role but very few that do it well at a truly global scale.
The Amazon cloud infrastructure is an excellent platform for businesses of all sizes to build robust and extremely scalable applications without the investment in infrastructure. Amazon
servers are distributed throughout the world and they provide multiple services to ensure the fastest possible response times globally. This isn’t recent news. What’s interesting is some of the new services that amazon provides to allow developers to more quickly build out
functionality without the need to manage the underlying servers.
This month, November 2014, Amazon announced new additions to its web services offering. Included in this announcement is AWS Lambda, a fast scaleable cloud computing service integrated with AWS services and custom event triggers. What sets Lambda apart is that all you need to upload is a .zip file with your Node.js code and set up a trigger when that code should run…that’s it…done.
Imagine a simple app, it allows users to upload an image. The user’s image needs to be cropped and converted to greyscale by a server. Amazon for years has provided a great service called S3 for mass storage of files like images etc. Amazon S3 allows you to emit a notification to listening services in AWS to respond to changes.
There are two main approaches we can take to building out our app:
#1 Build a service:
Developers can spin up a Linux or Windows server virtual instance on Amazon EC2 (Elastic Cloud) and write some code to listen to S3 events and respond to changes. As the load for the servers increases new instances of the server have to be created to handle the load. This generation of new servers is called horizontal scaling. In this type of scaling we are creating new full stack server instances automatically to respond to the load of the app. This is how we have been building cloud apps for a few years, and it’s worked well.
#2 Use a AWS Lambda Function
Instead of provisioning Linux/Windows servers that are running 24/7 to listen for events ($$$); Lambda allows you to take away all the server maintenance and complexity. In just a bit of code and configuration you can create stateless code that is triggered
automatically without all the hassle of worrying about provisioning scaling and maintenance. These stateless functions, because they don’t maintain any data, can be spun up into thousands of instances automatically in order to process the incoming events as required. You are not paying to have a server running 24/7, especially when
there are no requests coming in.
Currently the AWS Lambda service supports Node.js as it’s only language, with more to come as the service matures. This is a great use case for Node.js as it’s extremely fast to execute when written properly, and is easy to learn.
If you have a use case similar to this, the costs to scale can be of great benefit to your business. Instead of running one or more full stack servers 24/7 you are charged only by the compute time
required for the function and number of requests made. The calculations for this can be a bit confusing, but Amazon has provided some examples that showcase the cost benefits of this kind of approach.
“If you allocated 128MB of memory to your function, executed it 30 million times in one month, and it ran for 200ms each time…Total charges = Compute charges + Request charges = $5.83 + $5.80 = $11.63 per month”
Not too bad!
When you are looking to build your application out, take a look at what the different services offer. Often we build Amazon Lambda type services ourselves, this new service allows you to focus on your code and business logic reducing the time required to get apps to market.
If you have any questions about this topic, or other Mobile or Desktop Application topics feel free to call, or ask in the comments below.