DEV Community

Cover image for Implementing Microservices on AWS
Gurudev Prasad Teketi
Gurudev Prasad Teketi

Posted on

Implementing Microservices on AWS

Microservices are essentially small, independent units that make up an application.

Image description

APIs are considered the front door of microservices, as they are the entry point for application logic. Typically, RESTful web services API or GraphQL APIs are used. These APIs manage and process client calls, handling functions such as traffic management, request filtering, routing, caching, authentication, and authorization.

AWS offers building blocks to develop microservices, including

  • Amazon ECS and Amazon EKS for container orchestration engines.
  • AWS Fargate and EC2 as hosting options.
  • AWS Lambda for serverless way to build microservices.

Data Storage

AWS offers Memcached and Redis technologies as part of the managed Amazon ElastiCache service to store session data.
Putting a cache between application servers and a database is a common mechanism for reducing the read load on the database

AWS offers six relational database engines (Microsoft SQL Server, Oracle, MySQL, MariaDB, PostgreSQL, and Amazon Aurora) as managed services through Amazon Relational Database Service (Amazon RDS),however these are not designed for endless scale, which can make it difficult and time intensive to apply techniques to support a high number of queries.

On the NoSQL databases Amazon DynamoDB can be used to create a database table that can store and retrieve any amount of data and serve any level of request traffic. DynamoDB Accelerator (DAX) provides caching capabilities for accessing data to facilitate certain use cases that require response times in microseconds.

API management

Managing APIs can be time-consuming, especially when considering multiple versions, stages of the development cycle, authorization, and other features like throttling and caching.AWS offers API Gateway, ALB (Application Load Balancer) or NLB (Network Load Balancer) for API management.

Image description

Disaster recovery (DR)

Microservices applications often follow the Twelve-Factor Application patterns, where processes are stateless, and persistent data is stored in stateful backing services like databases. This simplifies disaster recovery (DR) because if a service fails, it's easy to launch new instances to restore functionality.Organizations should plan for recovery time objective (RTO) and recovery point objective (RPO). RTO is the maximum acceptable delay between service interruption and restoration, while RPO is the maximum time since the last data recovery point.

High availability (HA)

  1. Amazon EKS provides high availability by running Kubernetes control and data plane instances across multiple Availability Zones. It automatically detects and replaces unhealthy control plane instances and provides automated version upgrades and patching.
  2. Amazon ECR uses Amazon Simple Storage Service (Amazon S3) for storage to make your container images highly available and accessible. I
  3. Amazon ECSis a regional service that simplifies running containers in a highly available manner across multiple Availability Zones within a Region, offering multiple scheduling strategies that place containers for resource needs and availability requirements.
  4. AWS Lambda operates in multiple Availability Zones, ensuring availability during service interruptions in a single zone. If connecting your function to a VPC, specify subnets in multiple Availability Zones for high availability.

Configuration Management

  1. AWS App Config, it is a feature of AWS Systems Manager which makes it easy for customers to quickly and safely configure, validate, and deploy feature flags and application configuration. AWS App Config. It’s a feature of AWS Systems Manager which makes it easy for customers to quickly and safely configure, validate, and deploy feature flags and application configuration.
  2. GitOps is an innovative approach to configuration management that uses Git as the source of truth for all configuration changes.

Secrets Management

AWS offers secure services like AWS Systems Manager Parameter Store and AWS Secrets Manager. These tools can send secrets to containers in Amazon EKS as volumes, or to Amazon ECS as environment variables. In AWS Lambda, environment variables are made available to your code automatically. 

Cost optimization and sustainability

  1. By breaking an application into smaller parts, you can scale up only the services that need more resources, reducing cost and waste.
  2. Developers can do smaller updates, and reduce the resources spent on end to end testing.
  3. Stateless components (services that store state in an external data store instead of a local data store) in your architecture can make use of Amazon EC2 Spot Instances.

Communication Mechanisms

REST-based communication uses HTTP/S protocol, used broadly for synchronous communication between microservices, often operates through RESTful APIs.
GraphQL is a widespread method for synchronous communication, using the same protocols as REST but limiting exposure to a single endpoint.
gRPC is a synchronous, lightweight, high performance, open-source RPC communication protocol.

Asynchronous Messaging and Event Passing

Messaging can be defined of the following three types:

  1. Message Queues
  2. Publish-Subscribe
  3. Event-Driven Messaging

AWS offers various managed services such as

  1. Amazon Simple Queue Service (Amazon SQS) and Amazon Simple Notification Service (Amazon SNS) - Amazon SQS providing a space for storing messages and Amazon SNS enabling delivery of messages to multiple subscribers.
  2. **Amazon EventBridge **is a serverless service that uses events to connect application components together, making it easier for you to build scalable event-driven applications.
  3. Amazon MQ is a good choice if you have a pre-existing messaging system that uses standard protocols like JMS, AMQP, or similar.
  4. Amazon MSK (Managed Kafka) is a messaging system for storing and reading messages, useful for real-time message streaming.
  5. Amazon Kinesis is real-time processing and analyzing of streaming data. Image description

Observability

  1. Monitoring - AWS CloudWatch offers system-wide visibility into resource utilization, application performance, and operational health.
  2. Centralizing logs - AWS provides services like Amazon S3, CloudWatch Logs, and Amazon OpenSearch Service to centralize log files.
  3. Distributed tracing- AWS X-Ray uses correlation IDs to track requests across these services. X-Ray works with Amazon EC2, Amazon ECS, Lambda, and Elastic Beanstalk.
  4. Log analysis- Amazon CloudWatch Logs Insights allows for real-time log exploration, analysis, and visualization. Image description Image description

Managing Chattiness in Microservices Communication

  • Some key tools for managing chattiness are REST APIs, HTTP APIs and gRPC APIs. REST APIs offer a range of advanced features such as API keys, per-client throttling, request validation, AWS WAF integration, or private API endpoints.
  • Often, microservices use REST over HTTP for communication due to its widespread use. But in high-volume situations, REST's overhead can cause performance issues. It’s because the communication uses TCP handshake which is required for every new request. In such cases, gRPC API is a better choice. gRPC reduces the latency as it allows multiple requests over a single TCP connection. gRPC also supports bi-directional streaming, allowing clients and servers to send and receive messages at the same time.

Auditing

  1. AWS CloudTrail, which logs all API calls made in AWS, and AWS CloudWatch, which is used to capture application logs allows you to track changes and analyze behavior across your microservices.
  2. Amazon EventBridge can react to system changes quickly, notifying the right people or even automatically starting workflows to resolve issues. Image description

Resource Inventory and Change Management

AWS Config Rules provide a managed approach to monitoring changes across microservices. They enable the definition of specific security policies that automatically detect, track, and send alerts on policy violations.
Image description

AWS, with its robust suite of managed services, empowers teams to build efficient microservices architectures and effectively minimize complexity.

Top comments (0)