Tuesday, December 1, 2020

AZ - Cosmos DB

Today’s applications are required to be highly responsive and always online. To achieve low latency and high availability, instances of these applications need to be deployed in data centers that are close to their users. Applications need to respond in real-time to large changes and make this data available to users in milliseconds.

Azure Cosmos DB is Microsoft's globally distributed, multi-model database service. With a click of a button, Cosmos DB enables you to elastically and independently scale throughput and storage across any number of Azure regions worldwide. You can elastically scale throughput and storage, and take advantage of fast, single-digit-millisecond data access using your favorite API.
Cosmos DB provides comprehensive service level agreements (SLAs) for throughput, latency, availability, and consistency guarantees, something no other database service offers.

Databases Supported in CosmosDB
  1. SQL
  2. MongoDB
  3. Cassandra
  4. Azure Tables
  5. Gremlin (Graph) 



Key Benefits 

  1. Global Distribution of Data: Cosmos DB enables you to build highly responsive and highly available applications worldwide. Cosmos DB transparently replicates your data wherever your users are, so your users can interact with a replica of the data that is closest to them.
    Cosmos DB allows you to add or remove any of the Azure regions to your Cosmos account at any time, with a click of a button. Cosmos DB will seamlessly replicate your data to all the regions associated with your Cosmos account while your application continues to be highly available.
  2. Highly Available: 99.999%
  3. Scalable Throughput and Storage
  4. Low Latency
    It guarantees less than 10 ms response time throughout the world
  5. Five consistency choices

    • Strong: This means that reads are guaranteed to see the most recent write
      Clients get the old value from all read regions until and unless a new committed value to write region synced to all read regions.
      After the point of time when it confirmed from all regions that value gets synced clients start to receive the new value.
      Ensures order of data client receives 
    • Bounded staleness: Most frequently chosen by globally distributed applications expecting low write latencies but total global order guarantees
      All read regions get synced at a specified time lag, till that time all-regions provide old value, after the specified point of time all regions provide new value.
      Ensures order of data client receives 
    • Session: Session consistency is most widely used consistency level both for single region as well as, globally distributed applications
      In the case of the distributed DB across regions, the client gets the value whatever present on the DB of the region it has started the session.
      When a new value updated in write region client of any read region will get that value when that will sync in clients DB region(where the client made his session).
      However, a client who committed new value will start to get new value from the time he committed

      Ensures order of data client receives
    • Consistent Prefix: Guarantees that reads never see out of order writes
      High performance like eventual
      Ensures order of data client receives
    • Eventual: The weakest form of consistency wherein a client may get the values which are older than the ones it had seen before, over time
      Does not ensure order of data client receives
  6. Schema & Index management
    Keeping database schema and indexes in-sync with an application’s schema is especially painful for globally distributed apps. With Cosmos DB, you do not need to deal with schema or index management.
  7. Battle Tested: Microsoft's mission-critical applications use it
  8. Global Presence: 54+ regions globally
  9. Secured: Data is encrypted at rest and in motion
  10. Fully Managed: You no need to worry about managing deployments to multi-data centers its taken care by Azure with licensing you opt.  
  11. Sparks: You can run Spark directly on data stored in Cosmos DB. This capability allows you to do low-latency, operational analytics at global scale without impacting transactional workloads operating directly against Cosmos DB



AWS - CloudFormation

Cloud Formation is a service used to build your infrastructure(AWS resources) in an automated way with a script file across regions as well as for multiple accounts.


A Stack is a collection of AWS resources that you can manage as a single unit. In other words, you can create, update, or delete a collection of resources by creating, updating, or deleting stacks. All the resources in a stack are defined by the stack's AWS CloudFormation template.

You need to create a template that describes all the AWS resources that you want (like EC2 instances or Amazon RDS DB instances, S3 buckets), and AWS CloudFormation takes care of provisioning and configuring those resources for you.
You don't need to individually create and configure AWS resources and figure out what's dependent on what, AWS CloudFormation handles all of that.



You can write cloudFormation script in Json or YAML.


Points to be Remember
  1. By default automatic rollback feature is enabled.
  2. You are charged if errors occured while launching CloudFormation and its rollback.
  3. CloudFormation is free, you pay for resources you use like EC2, S3 buckets.
  4. Stacks can wait using "WaitCondition" for applications to be provisioned.
  5. Fn:GetAtt can be used to get output data like instance ip, ELB IP, S3 bucket name etc.
  6. Route53 supported for new as well as existing hosted zones.
  7. Aliases, 'A' record can be created (DNS settings)
  8. IAM creation an assignment supported

Benefits
  • Modelling Infrastructure 
AWS CloudFormation allows you to model your entire infrastructure in a text file. It helps you to standardize infrastructure components used across your organization, enabling configuration compliance and faster troubleshooting.

  • Quickly Replicate the infrastructure
AWS CloudFormation provisions your resources in a safe, repeatable manner, allowing you to build and rebuild your infrastructure and applications, without having to perform manual actions or write custom scripts. CloudFormation takes care of determining the right operations to perform when managing your stack, and rolls back changes automatically if errors are detected.

When you use AWS CloudFormation, you can reuse your template to set up your resources consistently and repeatedly. Just describe your resources once and then provision the same resources over and over in multiple regions.

  • Easily Control and Track Changes to Your Infrastructure
Whenever you need updates in AWS resources, like changing EC2 instance size or changing maximum no of instances.
If you do it by ClodFormation and face any error in execution of new script it rollbacks and restores previous one.

You source control CloudFormation text files, so you have track of changes in the file and you can restore check any previous versions as well.  

CI/CD - Safe DB Changes/Migrations

Safe DB Migrations means updating your database schema without breaking the running application and without downtime . In real systems (A...