Azure Cosmos DB

Cosmos DB is a distributed database engine with core features provided for any type of implementation model.

Features of Cosmos DB

  • Turnkey global distribution

Cosmos DB enables global data distribution and availability as a configuration setting in the portal, via command-line or ARM template, making data replication to a new location within the chosen region as seamless as possible. Both manual and automatic failover is supported as well as multi-read and multi-write from primary and replica databases.

  • Elastic storage and throughput

Cosmos DB will automatically scale database storage and throughput in a pay for consumption based model. There is no need to pre-provision resources to account to future growth. Cosmos DB measures throughput in a standardized way referred to as Request Units (RUs) and can be considered as an abstraction of physical resources. RUs are provisioned per second, eg. 2000 RU/s.

Throughput is provisioned at a database or container level.

Container LevelDatabase Level
Isolated throughputContainers share throughput
  • Low latency

Microsoft’s financially back SLA provides performance metrics for read and write requests < 10 ms 99% of the time.

  • Flexible consistency model

Data replication options are available over 5 sliding scale consistency models to optimize the database for a specific workload. Consistency can be configured globally per connection.

Credit : https://docs.microsoft.com/en-us/azure/cosmos-db/consistency-levels
  • Enterprise-grade security

A unified security model exists across all APIs, providing built-in encryption at rest and in-transit. IP-based access control is supported.

To connect to a Cosmos DB, 2 pairs of keys, read-write and read-only are used and managed by the service to control access to the account and data.

APIs

Cosmos DB exposes data through a variety of models and APIs. When you request data using a specific API, Cosmos DB will automatically handle the translation of data from the underlying data format to the data model required for the API.

APIDescription
SQL APICore API with many unique features.

Supports JavaScript logic and SQL queries.
MongoDB APICompatible with MongoDB v3.2 protocol.

Supports aggregation pipeline.
Gremlin APICompatible with the Apache TinkerPop graph traversal language (Gremlin).

Returns results in GraphSON (extended JSON) format.
Table APIService-level compatibility with Azure Storage Tables.

Migrate applications with no code changes.
Cassandra APISupports Cassandra Query Language (CQL) v4 protocol.

Works out of the box with CQL shell.
etcd APIImplements etcd wire protocol.

Can be used as a backing store for Azure Kubernetes Service.

Resource Model

Data in Azure Cosmos DB is stored in a hierarchy of resources.

Indexing

Cosmos DB automatically indexes all fields within all items or documents by default. While indexing can be useful for many workloads, indexing all fields and items can have a performance impact on more complex data sets.

Performance optimization to control and tune indexing is possible to balance trade-offs between write and query performance.

Index policies can be created to configure indexes by specifying the following:

  • List of paths to index
  • Different types of indexing to perform
  • List of paths to exclude

Types of indexes

RangeHashSpatial
Provides comparison functionalityQuick lookup for exact match informationUsed for geographical information

Create a Function App in Azure Portal

Pre-requisites:

An Azure subscription
An existing resource group
An existing storage account

1) From the Azure portal Home page, select Create a resource

2) On the New page, select Compute > Function App

3) On the Basics tab, populate the following fields and then click on Next : Hosting

  • Subscription
  • Resource Group
  • Function App Name
  • Publish
  • Runtime Stack

Runtime stack is not required if you’ve selected to publish a Docker container

  • Version
  • Region

4) On the Hosting tab, populate the following fields and click on Next : Networking

  • Storage account
  • Operating System
  • Plan type

5) On the Networking tab, select the appropriate option for network injection and click on Next : Monitoring

6) On the Monitoring tab, Enable or Disable Application Insights and click on Next : Tags

7) On the Tags tab, create tags to categorize your function app and click on Next : Review + Create

8) Review the configuration details of the Function App and click on Create

Containerization with Docker

Containers are a powerful tool for isolating, packaging and shipping applications.

What are containers?

To understand what containers are, it is important to first understand virtualization & virtual machines (VMs). VMs enable multiple operating systems in a single set of hardware which provides benefits such as:

  • Effective resource allocation

If two VM’s share the same hardware, each VM can take advantage of any under-utilized resources in the hardware.

  • Application isolation

Applications running on different VMs do not have access to each other’s data.

Containers takes the idea of virtualization further, while VMs virtualize the hardware, containers virtualize the operating system. The unit of isolation is a container image and is smaller than a VM image.

A container is a self-contained unit of software that contains everything required to execute the software. Containers are portable and resource-efficient. Multiple containers can run on the same operating system while still running as separate isolated processes. Container images are hosted in container engines, eg. Docker.

A container image will behave the same on any container engine and will enable you to build applications locally and deploy the same container image to a test or production environment.

Docker

Containerization in the context of Docker is considered as a runtime instance of a Docker image that contains the following:

  • A Docker image
  • An execution environment
  • A standard set of instructions

Core elements of the Docker ecosystem

The differences between a VM and a container

Virtual Machine (VM)Container
Hosts one or more applicationsHosts the application and it’s dependencies
Contains the necessary binaries and librariesShares the OS kernel with other containers
Exposes the guest OS to interact with the applicationsNot coupled to infrastructure and only requires the Docker Engine to be installed on the host
Executes isolated processes in the user’s workspace on the host OS

Benefits for developers

  1. Applications are portable and packaged in a standard way which makes deployment easier and repeatable.
  2. Tests, packaging and integration can be automated in a consistent application lifecycle.
  3. Supports microservice architectures.
  4. Alleviates platform compatibility issues.
  5. Simplifies release management with reliable deployments that improves the speed and frequency of releases.
  6. Enables consistency between between development, testing and production environments.
  7. Supports scalability for workloads on-demand for different use cases.
  8. Any issues or bugs can be isolated for debugging at a container level.
  9. Supports continuous integration in a deployment pipeline.

Docker build process

Dockerfile

A Dockerfile is composed from a base image, you can find a repository of base images on Docker Hub which already contains the latest updates and security configurations. A Dockerfile contains a set of instructions for building the Docker image.

//Example of a Dockerfile that will execute on Ubuntu

FROM ubuntu
CMD echo "Hello Naiomi!"

Build a Dockerfile into an image

Build the Dockerfile into a Docker image within your preferred IDE or run the following command

docker image build [OPTIONS] PATH | URL | -

Run the Docker image

docker run {image-name}

View all Docker images

docker images