Simplified Microservices with AWS

Gayan Hewa
Microservices Practitioner Articles
3 min readJul 10, 2016

--

Microservice architecture is a hot topic these days. The concept in a nutshell speaks about decoupling applications into smaller services ( way smaller than traditional SOA apps ).

With Docker Microservices became much more easier with faster deployments and encapsulations of the services into a much more pluggable solution.

But this article is not to discuss about any of the widely discussed topic of Microservices nor Docker. Rather to evaluate and discuss how Lambda — Serverless offering from Amazon makes it easier to achieve this.

AWS Lambda lets you run code on demand in response to events. Lambda is a great service that comes in different capacities for processing and memory and a rich feature set like VPC integration , Native SNS triggers, API gateway etc

For traditional monolithic applications AWS Lambda offers a great way to offload certain aspects of functionality into smaller functional services. For those Solutions Architects and Technical consultants who are reluctant to try out something new and effective. Lambda offers the prefect way to convince your management why its worth while to consider a Microservices based architecture ( I personally prefer a hybrid architecture for most startups).

Lets discuss with an example , consider a scenario where you have a standard , no frills membership site. A common service thats used by many of these websites is sending out E-mails. Emails get sent on certain events like : Registration , Password Reset , System Notifications etc.

If we look into offloading the Email processing as its a best practice to make sure your web servers don’t have to process anything thats outside their scope of work. There are two approaches we can use :

  1. Queue based
Traditional Messaging Queue Based Approach

2. Lambda Based

Lambda Based Approach

In contrast the both above methods serve the purpose of decoupling the email service. But the first approach , requires you to maintain a Messaging Queue ( ie. AWS SQS ) and a Worker function running 24/7 polling the queue for new messages to process the emails. If you think of it in a cost perspective you need to provision for additional hardware or have EC2 instances running either on demand or in a spot fleet with an autoscaling group depending on your architecture decisions.

On the other hand the Lambda based approach , you will only consume SNS to publish a message and in return SNS will invoke the Lambda function and process the message. If you look at it in a cost perspective, it costs less than $1 to process a million emails.

Another great use case is Mobile analytics. Imagine a use case where you have an analytics dashboard and all your mobile clients push data for the dashboard to visualize. Ideally we would have an api endpoint that collects this information and process and persist for the dashboard to be able to query them out.

Analytics Processing

One of the key advantages is the ability to offload the message formatting and pushing it out to the client. And the web application will never have to be called to push the data to the Database. It can be done directly from Lambda.

--

--