Embracing the Serverless Cloud-Native Approach

Sagar Gheewala / Sr. Backend Developer

The evolution of cloud computing has seen a significant shift towards serverless architectures, particularly for building robust, scalable, and cost-efficient applications.

Let’s explore this paradigm using a ridesharing app as our illustrative example, delving deeper into the technical intricacies and advantages, while leveraging a broader range of serverless services.

The Serverless Ridesharing App

Following are some of the most common features required for a Ride Sharing application. We will look at some of these features and how it can be associated to a matching AWS service.

Key Features for a Ride Sharing Application

Ride User Management:

  • Lambda Functions: AWS Lambda functions manage user registration, profile updates, and authentication. When a user signs up or updates their profile, the request is handled by a specific Lambda function.
  • API Gateway: Amazon API Gateway serves as the entry point, routing HTTP requests to the appropriate Lambda functions. It also handles RESTful APIs for the user management system, ensuring secure and efficient request processing.
  • Cognito Integration: AWS Cognito can be integrated for managing user pools and authentication workflows, enhancing security and streamlining user management.

Driver Management:

  • Lambda Functions: Similar to ride user management, Lambda functions are responsible for managing driver information, including registration, status updates, and availability.
  • API Gateway: API Gateway routes requests related to driver management to the corresponding Lambda functions, maintaining the separation of concerns and modularity.
  • Cognito Integration: Assuming Drivers are using separate application to interact with the system, AWS Cognito can be integrated for managing user pools and authentication workflows, enhancing security and streamlining user management. Cognito can be used for custom authentication strategies like OTP-based authentication flow instead of standard email/password. It's very likely that in many regions, drivers are not used to having their own email address.

Mapping and Routing:

  • Lambda Functions: These functions interact with external mapping services like Google Maps, Esri, HERE or AWS Location Service to calculate optimal routes. When a user requests a ride, the Lambda function processes the request and fetches routing information.
  • AWS IoT MQTT: This can be used to reliably ingest driver current location and use it for location updates, filtering, and search.
Reference Architecture for Connected Vehicle System on AWS
  • API Gateway: Manages the request and response lifecycle, ensuring that mapping and routing requests are efficiently handled and securely transmitted.

Payment Processing:

  • Lambda Functions: Payment processing is handled by Lambda functions integrated with payment gateways like Stripe. These functions ensure secure handling of payment transactions, including validation, processing, and logging.
  • API Gateway: Triggers the payment processing Lambda functions upon receiving payment requests, ensuring a seamless transaction flow. API Gateway can be used effectively to build the Webhooks that can receive external events from systems like Payment Gateways in case of payment confirmation or errors.

Data Storage:

  • Amazon S3: User and ride data, such as profile pictures, car picture, and ride receipts, are stored in Amazon S3 buckets. S3 provides durable and scalable storage, ensuring that data is securely managed and easily accessible.
  • Amazon DynamoDB: A NoSQL database service used for storing user and driver information, ride details, and transaction histories. DynamoDB offers low-latency data access and high scalability. DynamoDB can really shine and offer greater performance where the information is required with specific keys.

Content Delivery:

  • Amazon CloudFront: This service distributes static content, such as images and ride confirmation pages, ensuring low latency and high availability for users across the globe.

Orchestration and Workflow:

  • AWS Step Functions: This service orchestrates complex workflows, such as multi-step ride booking processes that involve checking driver availability, calculating routes, and confirming payments. Step Functions manage state transitions and error handling. This can be very useful service in complex situations like finding drivers based on parameters and extending lookup process.

Event Management:

  • Amazon EventBridge: Event-driven architecture is implemented using EventBridge to handle events like user registration, ride booking, and payment processing. EventBridge enables seamless integration between various services and ensures real-time event processing.

Driver Search based on Location

While all the above stands true, there is one general problem with this use case and Serverless architecture. For ride sharing, we need to find the drivers in a radius of the user location. This is something not easy to do with current Serverless options.

Amazon Location Service does provide the option to write and search locations based on parameters, and it's serverless. But it might be costly depening on the number of operations required.

Technical Deep Dive: Why Serverless Infrastructure Shines

True Scalability:

  • Auto-Scaling: AWS Lambda functions automatically scale based on the number of incoming requests. This automatic scaling ensures that the application can handle varying loads without manual intervention.
  • Concurrency Management: Lambda provides concurrency controls and throttling mechanisms, ensuring that the system remains resilient under high load conditions.

Cost Efficiency:

  • Pay-Per-Use: You only incur costs for the compute time consumed by your functions. There are no charges for idle time, making it highly cost-effective, especially for applications with variable traffic.
  • Resource Optimization: Lambda’s pricing model encourages efficient use of resources, promoting best practices in code optimization and execution efficiency.

Please refer to the AWS Serverless Free Tier and check the Always Free or 12 Months Free Tier services for detail on cost calculations. Do keep in mind that every service may have multiple level of cost calculations.

Simplified Operations:

  • No Server Management: Serverless abstracts away the need to manage underlying servers. Developers focus purely on business logic, significantly reducing operational overhead.
  • Built-In Monitoring: AWS provides integrated monitoring tools like CloudWatch and X-Ray for tracking Lambda function performance, errors, and invocations, facilitating easy debugging and optimization.

Serverless and Microservices: A Symbiotic Relationship

Modular Architecture:

  • Microservices Implementation: Each Lambda function can be considered a microservice, responsible for a single piece of functionality. This aligns perfectly with microservices architecture principles.
  • API Gateway Coordination: API Gateway orchestrates these microservices, managing the flow of data and interactions between different services.

Addressing Tradeoffs

Cold Starts:

  • Mitigation Strategies: Cold starts can cause latency during the initial invocation of a Lambda function. This can be mitigated using techniques like provisioned concurrency, which keeps Lambda functions warm and ready to handle requests.
  • Optimal Configuration: Careful configuration of Lambda function memory and timeout settings can also help reduce cold start impact. There are language-spacific improvements like SnapStart for Java for performance improvements. We prefer to use NodeJS for most of our deployments.

Execution Time Limits:

  • 15-Minute Limit: Lambda functions can only have a maximum execution time of 15 minutes. For tasks that exceed this limit, consider breaking them into smaller, sequential functions or using other AWS services like AWS Step Functions or AWS Batch. For long running tasks that can't be easily broken into smaller tasks, AWS Fargate with ECS can be a perfect option.

When to Choose Serverless

Event-Driven Execution:

  • Reactive Architecture: Serverless is ideal for applications that respond to real-time events such as user actions, data changes, or system events. Lambda functions can be triggered by various AWS services like EventBridge, S3, DynamoDB, or SNS.

Variable Traffic Patterns:

  • Dynamic Scaling: Serverless architectures excel in environments with unpredictable traffic patterns. Whether it’s handling peak loads or scaling down during off-peak times, serverless ensures consistent performance. Lambda functions can scale to thousands of parallel instances (although this needs to plan carefully) based on demand.

Cost Optimization:

  • Eliminating Idle Costs: By only paying for actual compute usage, serverless significantly reduces costs associated with idle infrastructure, making it an economical choice for many applications. It's easy to configure different Lambda functions with different resource configurations based on the internal logic.

Summary

The serverless cloud-native approach revolutionizes how applications are built and managed, offering unparalleled scalability, cost efficiency, and operational simplicity. By leveraging a suite of AWS serverless services, developers can build robust, modular, and highly responsive applications like our ridesharing app example.

While there are tradeoffs to consider, the benefits often far outweigh the challenges, making serverless a compelling choice for modern cloud-native application development.

More articles

Celebrating a Decade of Innovation: Kubernetes and AWS Lambda

The last ten years have been a transformative period in the world of technology, marked by the emergence and maturation of two groundbreaking technologies: Kubernetes and AWS Lambda. As Kubernetes celebrates its 10th anniversary and AWS Lambda approaches the same milestone in coming months, it's an opportune moment to highlight on their substantial impact on application development and management.

Read more

How to Build an Android React Native Application Using AWS CodePipeline

In this blog post, we'll walk you through the process of using AWS CodePipeline, along with other AWS services, to build an Android React Native application. We'll be using an AWS CodeCommit Git repository to store our code and an S3 bucket to save the final generated APK.

Read more

Tell us about your project

Our office

  • 408-409, SNS Platina
    Opp Shrenik Residecy
    Vesu, Surat, India
    Google Map