Serverless with AWS

Sudheer Kumar
4 min readMar 16, 2021

--

Photo by Clay Banks on Unsplash

Serverless is a great architecture model and AWS has got great managed services and tools that support the serverless architecture. In this article, I am going to talk about the support towards Serverless that is in-built in AWS platform.

AWS Serverless Components

  1. S3 : Simple storage service that can scale infinite storage and great scalability. It provides various classes of storage like S3 Standard, S3-IT (Intelligent Tiering), S3 Standard-Infrequent Access (IA), One Zone-IA, S3 Glacier & S3-Glacier Deep Archive.
  2. Data Stores: Amazon RDS DBs belong to PaaS as AWS takes care of maintaining the database, patching etc. Truly serverless DB options on AWS are DynamnoDB and Aurora Serverless.
  3. Compute: You have AWS Lambda functions for Compute and AWS Step functions, which can make use of Lambda functions for orchestration of your business functionalities. But Lambda has got limitations like 15 min max execution time, 1000 concurrent requests per account or 3G max RAM. So if they become restrictive, then you have AWS Fargate — that provides managed serverless Container-based solution.
  4. SQS : provides flexible store and process with even fan-out options.
  5. SNS : Provides support for Publish-Subscribe feature
  6. Streaming Services: Kinesis Provides scalable streaming services for IoT, data transformation etc.

Serverless Microservices

Serverless Microservice implementation on AWS have either Lambda functions or Fargate containers as their computing resource. They are interfaced to the external world through REST API through API Gateway or GraphQL API through APpSync managed service.

The figure below shows the architecture of a serverless microservice with AWS Lambda where the complete service is built out of managed services, which eliminates the architectural burden to design for scale and high availability and eliminates the operational efforts of running and monitoring the microservice’s underlying infrastructure.

Microservice using API Gateway and Managed Services

Lambda has got some constraints on max execution time (15 mins), max memory (3GB)usage as well as max size of the Lambda executable (250 MB). So a rule of thumb could be to start with Lambda and up on constrained, upgrade the function to Fargate containers. The figure below shows a similar implementation that is also based on serverless services. In this architecture, Docker containers are used with AWS Fargate, so it’s not necessary to care about the underlying infrastructure.

API Gateway with Fargate

The figure below shows GraphQL APIs built with AWS AppSync, give front-end developers the ability to query multiple databases, microservices, and APIs from a single GraphQL endpoint.

GraphQL API Gateway

Patterns for Distributed Serverless Architectures

While designing a complex system using a set of disconnected components, keep the following points in mind.

  • Direct service calls either sync or async will create tight coupling
  • Producer/Consumer pattern (SNS) can bring more decoupling
  • Data Pipeline: In this case, the product is not concerned about the output, but it passes to the next component in the pipeline.

SQS service could be useful for implementing Producer/Consumer patterns. But please note that one message will be consumed only once by a consumer (eg: Lambda function). If you have set a concurrency limit for a Lambda function, then multiple messages could be processed parallelly, as per the concurrency limit set.

If you need to process the same message by multiple consumers, it will be a good idea to fan-out the message using SNS to the required consumers.

Kinesis buffers messages from consumers and the messages are retained, unlike SQS or SNS. Kinesis design will consist of topics for which there could be multiple consumers. Ordering of the messages is also guaranteed. There could be multiple shards with-in a stream and consumers could be assigned for each shard. Kinesis also supports replaying the messages by resetting the stream to a point in time.

Now a complex Serverless system can’t be designed and managed with out a framework that helps with development, CI/CD, versioning etc.. There are 2 major frameworks that help us with the Serverless requirements : AWS SAM & Serverless framework. Serverless framework being cross cloud platform, I am going to focus on Serverless now. More about that later….

--

--

Sudheer Kumar
Sudheer Kumar

Written by Sudheer Kumar

Experienced Cloud Architect, Infrastrcuture Automation, Technical Mentor

No responses yet