8 mins read 
By  Thisal De Silva    Posted on  

Blogger, software engineer and technologist Thisal de Silva gives us a brief introduction to the serverless-AWS Lambda function. This is a precursor to his next article on how and why the engineering team at WealthOS use Lambdas in the platform. 

Putting Lambda Functions in context

First, AWS Lambda functions in the broader context of computer science and software engineering.

Out with the old…

Legacy systems are monolithic, which translates to an entire application coded as one single unit with interconnected and interdependent components of the applications. This is of course unlike the loosely coupled microservices or nanoservices architecture that is widely used in the industry today, including the WealthOS platform.

Just so you can understand the benefits of modern-day system architectures, I have provided a simplistic comparison of the main differences between monolithic architecture and microservice architecture (please note that this is just a high-level description).

The diagram below shows you the difference between scaling up an application on a monolithic vs. microservices/nanoservices based design. What you see is that the monolithic system will require the entire code block to be replicated. While microservices architecture allows you to scale the required resource independently.

For example, suppose you have a component that registers users for the system (assume the triangle in the diagram below is a user-register service) and the number of registrations keeps increasing. In that case, you only need to deploy more instances of that specific service. Unlike in a monolithic system, the entire application does not need to be deployed.

And in with the new.

I wouldn’t say that microservices or nanoservices are automatically better than monolithic architecture, as each has its pros and cons, I would rather say that it depends on the most appropriate architecture for the application requirements at hand. Today we see that engineers are trending toward SOA (service-oriented architecture), microservice architecture and nanoservice architecture. Because the idea of creating segregated services has been identified as a more flexible style of architecture. This increases many attributes related to overall product delivery and product quality, especially alongside the use of CI/CD (continuous integration and continuous delivery).  

The popularity of these loosely coupled and highly cohesive modern-day architectures means that cloud computing and cloud platform providers put more emphasis on targeting these philosophies. 

As a consequence, AWS lambda, which is Amazon’s flavour of serverless functions in the context of cloud computing, enables us to deploy modern-day applications into AWS. The key point  here is that AWS lambda is not an architecture but it is a deployment mechanism that is well suited to nanoservice or microservices.

Introducing the AWS Lambda Function

Pros and cons of AWS lambda function usage. 

Previously I mentioned that nanoservices and microservices provide scalability. With AWS lambda functions this scalability is even more enhanced. 

How AWS Lambdas enhance system scalability

We can achieve system scalability with two approaches. Horizontal scaling and vertical scaling. For example, if you have an existing system that runs on a single server, and this was running well for nine months with an average load of ten requests per minute. However, during the high season, the number of requests increases to 17 per minute and the server struggles to function. Now you need to find a way to support this load. 

One thing you can do is, increase the hardware inside the server you have (increase processor, ram etc.), this is vertical scaling. Another thing you can do is, purchase an additional server and spread out the requests among them. This is horizontal scaling. 

In any system, there are limitations associated with each option. Vertical scaling is supported up to some extent only, and horizontal scaling needs to be incorporated into the system at some point if you need high scalability and fault tolerance (ability to withstand hardware or software failure). 

Even by nature, horizontal scaling is the way to move forward and, AWS Lambda architecture invokes multiple alike lambda instances (horizontal scaling) effortlessly (not considering the cold start here). Since AWS creates multiple lambda instances based on  the number of requests coming into the system (one way of invoking lambda and the most commonly used mechanism within WealthOS platform), it automatically scales up and down (horizontally). In addition, you only need to pay for your invocations, making  this  a very cost-effective solution for most situations. Even though modern-day architectures provide scalability, this much flexibility is only achievable via serverless functions (the AWS version of which is the lambda function). 

All in all, AWS lambda is a great choice for tasks that run for a short period of time. Watch this space for how we designed a workaround to make long-running bulk operations possible on lambda infrastructure.  

Read more