Monday, February 20, 2017

We continue with a detailed study of Microsoft Azure stack as inferred from an introduction of Azure by Microsoft. We reviewed some more features of Azure networking and started discussing Azure storage.
The IaaS offerings from Azure storage services include disks and files where as the PaaS offerings from Azure storage services include objects, tables and queues. The storage offerings are built on a unified distributed storage system with guarantees for durability, encryption at Rest, strongly consistent replication, fault tolerance and auto load balancing.  Disks are offered with server side encryption at rest and Azure disk encryption with BitLocker/DMCrypt. In addition, disks come with blob cache technology, enterprise grade durability with three replicas, snapshot for backup, ability to expand disks, and REST interface for developers. 
Azure files is a fully managed cloud file storage for use with IaaS and on-premise instances. Azure blobs are of three types - Block blobs, Append blobs, Page blobs.
The blob storage is tiered.  There are two tiers - hot tier and cold tier.  Hot is used for commonly used data and cold for rarely used data. The redundancy features are handled by storage stamps and a location service.
A storage stamp is a cluster of N racks of storage nodes, where each rack is built out as a separate fault domain with redundant networking and power.  Each storage stamp is located by a VIP  and served by layers of Front-Ends, partition layer and stream layer that provides intra stamp replication
The stream layer stores bits on the disk and is in charge of distributing and replicating the data across many servers to keep data durable within a storage stamp. It behaves like a distributed file system except files are called streams but the functionality is essentially just for storage and replication. The partition layer is built for managing and understanding the higher level data abstractions (Blob, table and queue), providing a scalable object namespace,  providing transaction ordering and strong consistency of objects and storing object data on top of the stream layer and caching object data to reduce disk I/O.
The front-end layer is a collection of stateless servers that handle incoming requests.
There are two replication engines within the system and they have separate responsibilities.  These are intra-stamp replication which is handled by the stream layer and the inter-stamp replication which is handled by the partition layer. Interstamp replicates objects and the transactions applied to those objects, whereas intra-stamp replication replicates blocks of disk-storage that are used to make up the objects.
#codingexercise
Find the number of inversions in an unsorted array. For example: 8,4,2,1 has an inversion count of 6 and inversions as (8,4), (8,2), (8,1),(4,2),(4,1),(2,1)
// partial example
int GetInversionCount(List<int> A)
{
Node root = null;
int result = 0;
for(int I =0; I < A.Count; i++)
     root = insert(int A[i], ref root, ref result);
return result;
}
Node insert(int key, ref Node root, ref int result)
{
if (root == null) return new Node(key);
if (key < root.key)
{
     root.left = insert(key, ref root.left, ref result);
     result = result + treesize(root.right) + 1;
}else{
     root.right  = insert(key, ref root.right, ref result);
}
node.height = max(treeheight(root.left), treeheight(root.right)) + 1;
node.size = treesize(root.left)+treesize(root.right)+1;
// AVL Balance the tree at root as shown earlier
:
:

// if the tree is right heavy and the node is less than the left then right rotate to compensate
// if the tree is left heavy and the node is greater than the right, then left rotate to compensate
// if the tree is right heavy and the node is greater than the left, then left rotate the left sibling then right rotate the root to compensate
// if the tree is left heavy and the node is greater than the right, then right rotate the right subtree and then left rotate the root
// essentially we maintain the balance and the BST rooted at the middle of the length of the sorted sequence and prgoress towards the finish where the finished sequence is also balanced. The invariants during the progress are the sorted sequence for inorder and the balance maintained by the BST and the AVL respectively.

return result;
}
}

Sunday, February 19, 2017

We continue with a detailed study of Microsoft Azure stack as inferred from an introduction of Azure by Microsoft. We reviewed some more features of Azure networking and started discussing Azure storage.The IaaS offerings from Azure storage services include disks and files where as the PaaS offerings from Azure storage services include objects, tables and queues. The storage offerings are built on a unified distributed storage system with guarantees for durability, encryption at Rest, strongly consistent replication, fault tolerance and auto load balancing.  Disks are of two types in Azure  - Premium disks (SSD) and Standard Disks (HDD) and are backed by page blobs in Azure storage Disks are offered with server side encryption at rest and Azure disk encryption with BitLocker/DMCrypt. In addition, disks come with blob cache technology, enterprise grade durability with three replicas, snapshot for backup, ability to expand disks, and REST interface for developers. Azure files is a fully managed cloud file storage for use with IaaS and on-premise instances. The scenarios cover include lift and shift, host high availability workload data and backup and disaster recovery. 
Azure blobs are of three types - Block blobs, Append blobs, Page blobs. The blob storage is tiered.  There are two tiers - hot tier and cold tier.  Hot is used for commonly used data and cold for rarely used data. The redundancy options include Locally Redundant Storage aka LRS, Geo Redundant Storage aka GRS and Read Access - Geo Redundant Storage aka RA-GRS.
The redundancy features are handled by storage stamps and a location service.
A storage stamp is a cluster of N racks of storage nodes, where each rack is built out as a separate fault domain with redundant networking and power.  CEach storage stamp is located by a VIP  and served by layers of Front-Ends, partition layer and stream layer that provides intra stamp replication.
The stream layer stores bits on the disk and is in charge of distributing and replicating the data across many servers to keep data durable within a storage stamp. It behaves like a distributed file system except files are called streams but the functionality is essentially just for storage and replication. 
The data is stored in the stream layer but is accessible from partition layer.  The partition servers and stream servers are usually together in the same storage stamp. 
Since the stream layer does not understand the higher level constructs, the partition layer is built for (a) managing and understanding the higher level data abstractions (Blob, table and queue), (b) providing a scalable object namespace, (c) providing transaction ordering and strong consistency of objects and (d) storing object data on top of the stream layer and (e) caching object data to reduce disk I/O.
The front-end layer is a collection of stateless servers that handle incoming requests.

#design_idea : https://1drv.ms/w/s!Ashlm-Nw-wnWrwbnnkOk10IVata4 
#codingexercise
Print common elements of two binary trees:
List<Node> GetCommonElements(Node root1, Node root2)
{
var list1 = new List<Node>();
var list2 = new List<Node>();
ToInOrder(root1, ref list1);
ToInOrder(root2, ref list2);
return list1.Intersect(list2).ToList();
}

We can also count inversions in an array using a BST. An inversion is an unsorted pair of elements. The idea is that by inserting into an AVL BST we keep track of the larger elements so we know how many inversions there are when we count the nodes from root to leaf that are higher than the node to be inserted.

Saturday, February 18, 2017

We continue with a detailed study of Microsoft Azure stack as inferred from an introduction of Azure by Microsoft. We reviewed some more features of Azure networking and started discussing Azure storage.The IaaS offerings from Azure storage services include disks and files where as the PaaS offerings from Azure storage services include objects, tables and queues. The storage offerings are built on a unified distributed storage system with guarantees for durability, encryption at Rest, strongly consistent replication, fault tolerance and auto load balancing.  Disks are of two types in Azure  - Premium disks (SSD) and Standard Disks (HDD) and are backed by page blobs in Azure storage Disks are offered out of about 26 Azure regions with server side encryption at rest and Azure disk encryption with BitLocker/DMCrypt. In addition, disks come with blob cache technology, enterprise grade durability with three replicas, snapshot for backup, ability to expand disks, and REST interface for developers.
Azure files is a fully managed cloud file storage for use with IaaS and on-premise instances. The scenarios cover include lift and shift, host high availability workload data and backup and disaster recovery. 
Azure blobs are of three types - Block blobs, Append blobs, Page blobs. Block blobs are used for document, images, video etc. Append blobs are used for multi-writer append only scenarios such as logging and big data analytics output. Page blobs are used for page aligned random reads and writes IaaS Disks, Event Hub, Block level backup. The blob storage is tiered.  There are two tiers - hot tier and cold tier.  Hot is used for commonly used data and cold for rarely used data.  The former is roughly 2.4cents per GB per month and the cold is one cent per GB per month. There is no charge for hot to cool switch.  Generally the rule of thumb is to pick hot tier when we have frequent use and to pick the cold tier when we have high volume. Both tiers are manageable with API that is identical and offers similar throughput and latency. The redundancy options include Locally Redundant Storage aka LRS, Geo Redundant Storage aka GRS and Read Access - Geo Redundant Storage aka RA-GRS.
In LRS, all data in the storage account is made durable by replicating transactions synchronously to three different storage nodes within the same region.
GRS is the default option for redundancy when a storage account is created. In addition to what LRS does, GRS also queues up asynchronous replication to another secondary region where another three more storage nodes are made available.
The RA-GRS gives read only access to a storage account's data in the secondary region from the GRS redundancy. Since the secondary region is used asynchronously, it will eventually have a consistent version of the data. LRS costs less than GRS and has higher throughput than GRS and is especially suited for applications that have their own geo replication strategy. 
The paper on Windows Azure Storage says that the system consists of storage stamps and location service.
A storage stamp is a cluster of N racks of storage nodes, where each rack is built out as a separate fault domain with redundant networking and power.  Clusters typically range from 10 to 20 racks with 18 disk heavy storage nodes per rack. Each storage stamp is located by a VIP  and served by layers of Front-Ends, partition layer and stream layer that provides intra stamp replication. Generally a storage stamps is kept 70% utilized in terms of capacity, transaction and bandwidth.  When a storage stamp reaches 70% utilization, the location service migrates accounts to different stamps using inter-stamp replication. 


#codingexercise 
Convert a BST into a Min Heap 
Node ToMinHeap(Node root) 
{ 
if (root == null) return null; 
var sorted = new List<Node>(); 
ToInOrderList(root, ref sorted); 
var heap = ToMinHeap(sorted); 
return heap; 
} 
void ToInOrderList(Node root, ref List<node> all) 
{ 
if (root == null) return; 
ToInOrderList(root.left, ref all); 
all.Add(root); 
ToInOrderList(root.right, ref all); 
} 
Void ToMinHeap(Node root, ref List<Node> sorted) 
{           
Sorted.ForEach(x = > {x.left = null; x.right = null;}); 
For (int I = 1; I < sorted.Count()/2; I++) 
                MinHeapify(sorted, i) 
} 
Void MinHeapify(List<Node> sorted, int i) 
{ 
Sorted[i-1].left =  ( 2 x i <= sorted.count ) ? sorted[2xi-1] : null; 
Sorted[i-1].right = (2 x I + 1 <= sorted.count) ? sorted[2xi+1-1] : null; 
} 
eg: 1 2 3 4 7 8 9 10 14 16
To heapify an unsorted list:
void Min_Heapify(List<Node> A, int i) // 1-based
{
int l = 2 * i;
int r = 2 * i + 1;
int smallest  = i;
if (l <= A.Count and A[l] < A[i])
    smallest = l;
else
   smallest = i;
if (r <= A.Count and A[r] < A[smallest])
   smallest = r;
if (smallest != i)
    Swap(A[i], A[smallest]);
    Min_Heapify(A, smallest);

}

Friday, February 17, 2017

We continue with a detailed study of Microsoft Azure stack as inferred from an introduction of Azure by Microsoft. We reviewed some more features of Azure networking.  We discussed global DNS, dual stacks for IPV4 and IPV6, and load balancers.Azure load balancer services come at different levels.- cross region, in-region, application gateway and individual vms.
Application Gateway can manage backend with rich diagnostics including access and performance logs, VM scale set support and custom health probes.
The Web Application Firewall security protects applications from web based intrusions and is built using ModSecurity and CoreRule set. It is highly available and fully managed. 
Microsoft Azure has way more express route locations than any other public cloud.Microsoft Azure has deeper insights into our network regardless of whether it is ExpressRoute, VirtualNetwork or ApplicationGateway 
We now review Azure storage stack.  The IaaS offerings from Azure storage services include disks and files where as the PaaS offerings from Azure storage services include objects, tables and queues. The storage offerings are built on a unified distributed storage system with guarantees for durability, encryption at Rest, strongly consistent replication, fault tolerance and auto load balancing.  The IaaS is made up of storage arrays, virtual machines and networking. The PaaS is made up of existing frameworks, web and mobile, microservices and serverless compute. 
Disks are of two types in Azure  - Premium disks (SSD) and Standard Disks (HDD) and are backed by page blobs in Azure storage.  Their capabilities are not diminished and offer high i/o performance and low latency > 80000 iops and > 2000 MB/sec disk throughput per VM.  Disks are offered out of about 26 Azure regions with server side encryption at rest and Azure disk encryption with BitLocker/DMCrypt. In addition, disks come with blob cache technology, enterprise grade durability with three replicas, snapshot for backup, ability to expand disks, and REST interface for developers. Azure has additionally released features called Azure Backup support, Encryption at Rest, Azure Site Recovery Preview and Incremental Snapshot Copy. In the future, it plans to expand on disk sizes and disk analytics enhancement. 
Azure files is a fully managed cloud file storage for use with IaaS and on-premise instances. The scenarios covered lift and shift, host high availability workload data and enables backup and disaster recovery. The Azure files support multiple protocols and operating systems. It has support for SMB 2.1 and 3.0  The files are globally accessible from both On Premise and IaaS instances. They are available in all Azure regions. There's high availability and durability for these files.
Azure files will support snapshots, AD integration, increase scale limits, larger share size, encryption at rest and Backup integration.  
Azure blobs are of three types - Block blobs, Append blobs, Page blobs. Block blobs are used for document, images, video etc. Append blobs are used for multi-writer append only scenarios such as logging and big data analytics output. Page blobs are used for page aligned random reads and writes IaaS disks, Event Hub, Block level backup.
#codingexercise
Convert a BST into a Min Heap
Node ToMinHeap(Node root)
{
if (root == null) return null;
var sorted = ToInOrderList(root);
var heap = ToMinHeap(sorted);
return heap;

https://1drv.ms/w/s!Ashlm-Nw-wnWrwTmE6AXT0d_sX3k

Thursday, February 16, 2017

We continue with a detailed study of Microsoft Azure stack as inferred from an introduction of Azure by Microsoft. We reviewed some more features of Azure networking.  We discussed global DNS, dual stacks for IPV4 and IPV6, and load balancers.
Azure load balancer services come at different levels. There is the traffic manager for cross region direction and availability and exposure to the internet.  There is the Azure Load Balancer which provides in-region scalability and availability. There is the Azure application gateway which has URL/content based routing and load balancing. Then there is load balancing on the VMs for web servers.
Load Balancers in Azure use multiple VIPs to simplify designs and reduce cost. They can be setup with internal and external VIP with direct public association. 
Application Gateway can manage backend with rich diagnostics including access and performance logs, VM scale set support and custom health probes.
The Web Application Firewall security protects applications from web based intrusions and is built using ModSecurity and CoreRule set. It is highly available and fully managed.
Cross premises connectivity is maintained with P2S SSTP tunnels and IPSEC S2S VPN tunnels to Azure over Internet. If there is a private WAN, an ExpressRoute is maintained to Azure.
There is dual redundancy with Active-Active gateways which is new in Microsoft Azure. This leads to zero downtime during planned maintenance. This is an improvement from active-standby to active-active. It supports both cross-premises and VNet to VNet connectivity and spreads traffic over multiple tunnels simultaneously. 
There are thirty five express route locations in Microsoft Azure which is more than any other cloud. This has nearly doubled peering locations and partners. There are also improvements in ExpressRoute It supports upto 10G throughputs to VNets where usually the standard is 1Gbps and the high performance is 2Gbps. It has the best cloud enterprise connectivity SLA. It offers more insights, self-help and troubleshooting tools, improved monitoring, diagnostics and alerting than others. We can also see BGP routes, traffic statistics, and ARP tables.
Microsoft Azure has deeper insights into our network regardless of whether it is ExpressRoute, VirtualNetwork or ApplicationGateway For example, the Express Route has peering connection statistics, ARP table, route summary, and route table. The Virtual network has effective security rules on every NIC, and next hop and effective routes for every NIC in the subnet. The Application Gateway has metrics and alerts and back end health information.
#codingexercise
Find pairs with given sums such that pair elements lie in different BSTs.
void GetPairSum(Node root1, Node root2, int sum)
{
var list1 = root1.ToInOrder();
var list2 = root2.ToInOrder();
int left = 0;
int right = list2.Count-1;
while ( left < list1.Count && right >= 0)
{
 if (list1[left] + list2[right] == sum)
{
    Console.WriteLine("{0}:{1}", list1[left], list2[right]);
    left++;
    right--;
}else if ( list1[left] + list2[right] < sum )
{
    left++;
}else
    right--;
}
}
It might be noted that this does not take care of duplicates.

Wednesday, February 15, 2017

We continue with a detailed study of Microsoft Azure stack as inferred from an introduction of Azure by Microsoft. We reviewed some more features of Azure networking. 
The global DNS name resolution is pretty fast with very high availability. It is integrated with the Azure Resource Manager for role based access control, tagging and template based deployment - for both zones and record sets. 
Azure virtual machines support native dual stacks : (IPV4+IPV6) on both flavors of the operating system. It is available globally. It maximizes the reach of Azure applications using mobile (4G) and IoT devices
Azure load balancer services come at different levels. There is the traffic manager for cross region direction and availability and exposure to the internet.  There is the Azure Load Balancer which provides in-region scalability and availability. There is the Azure application gateway which has URL/content based routing and load balancing. Then there is load balancing on the VMs for web servers.
Load Balancers in Azure use multiple VIPs to simplify designs and reduce cost. There are multiple private VIPs on a load balancer and the backend ports are reused using direct server return (DSR). Secondary NICs associated are also provided to enable connectivity to restricted vnet. Load balancer can now be setup with internal and external VIP with direct public association. Moreover, a NIC can now have multiple private IPs - static or dynamic and multiple public IPs - static or dynamic and unlocks NVA partners.  Application Gateway has layer 7 application delivery controller features. It can enforce security with SSL termination and allow/block SSL protocol versions. It can manage session and site with cookie based session affinity and muti-site hosting. It can manage content with URL based routing. It can manage backend with rich diagnostics including access and performance logs, VM scale set support and custom health probes.
The Web application firewall has also been significantly improved based on Open Web Application Security Project (owasp.org). WAF security protects applications from web based intrusions and is built using ModSecurity and CoreRule set. It is highly available and fully managed. It is preconfigured for most common web vulnerabilities such as SQL injection and XSS attacks.
Cross premises connectivity is maintained with P2S SSTP tunnels and IPSEC S2S VPN tunnels to Azure over Internet. If there is a private WAN, an ExpressRoute is maintained to Azure.
Print the largest BST in a given binary tree
int GetMaxBST(Node root)
{
if (IsBST(root))
    return treesize(root);
return Math.max( GetMaxBST(root.left), GetMaxBST(root.right));
}

bool isBST(node root)
{
return IsBstHelper(root, INT_MIN, INT_MAX);
}

bool IsBstHelper(node root, int min, int max)
{
 if (root==null) return true;
 if (root.data < min || root.data> max) return false;
return IsBstHelper(root.left, min, root.data-1) &&
           IsBstHelper(root.right, root.data+1, max);

}
int treesize(Node root)
{
if (root == null) return 0;
return treesize(root.left) + treesize(root.right) + 1;
}

we could also combine the operations above to make the traversals more efficient.
int GetMaxBST(node root, int min, int max)
{
if (root == null) return 0;
if (root.data < min || root.data > max) return 0;
int left = GetMaxBST(root.left, min, root.data - 1);
int right = GetMaxBST(root.right, root.data+1, max); 
if (left >= 0 && right >= 0)
    return  left + right + 1;
return 1; 

Tuesday, February 14, 2017

We continue with a detailed study of Microsoft Azure stack as inferred from an introduction of Azure by Microsoft. We discussed Azure stack is a hybrid approach to cloud. Microsoft Azure has developer tools for all platform services targeting web and mobile, Internet of Things, Microservices, and Data + analytics, Identity management, Media streaming, High Performance Compute and Cognitive services. These platform services all utilize core infrastructure of compute, networking, storage and security. The Azure resource manager has multiple resources, role based access control, custom tagging and self-service templates.
1)  The compute services are made more agile with the offerings from a VM infrastructure, VM scale sets infrastructure, Container service orchestration and batch/Job orchestration. 
2) The Paas platform of Azure can span Azure and AWS both. It can occupy on-Premise, GCP and others as well Containers, serverless and Microservices are different forms of computing. 
3) Azure provides a data platform. The Paas platform of Azure can span Azure and AWS both. It can occupy on-Premise, GCP and others as well Containers, serverless and Microservices are different forms of computing. The consumers for this data transformation to actions are people as well as apps and automated systems.
4) Azure Networking is divided into regions that include inside the Azure region, connecting Azure regions, and geographic reach and internet ecosystems. The networking inside the Azure region already comes with security, performance, load balancing, virtual networks, cross-premises connectivity. Azure comes with accelerated networking
We review some more features of Azure networking. Azure DNS is a globally distributed architecture which is resilient to multiple region failure. The global DNS name resolution is pretty fast with very high availability. It is integrated with the Azure Resource Manager for role based access control, tagging and template based deployment - for both zones and record sets. Azure DNS comes with REST API and SDKs for application integration.
Azure virtual machines support native dual stacks : (IPV4+IPV6) on both flavors of the operating system. It is available globally. It maximizes the reach of Azure applications using mobile (4G) and IoT devices
IPv6 is required by governments and their suppliers. IPV6 has AAAA record.
Azure load balancer services come at different levels. There is the traffic manager for cross region direction and availability and exposure to the internet.  There is the Azure Load Balancer which provides in-region scalability and availability. There is the Azure application gateway which has URL/content based routing and load balancing. Then there is load balancing on the VMs for web servers.
Load Balancers in Azure use multiple VIPs to simplify designs and reduce cost. There are multiple private VIPs on a load balancer and the backend ports are reused using direct server return (DSR) which comes in very useful when there is concern that the load balancer will become a bottleneck. In such cases, the servers are allowed to respond to the client directly such as when the requests are small but the responses are large.

#codingexercise
Find the closest element to a given value in a binary search tree

void GetMinDiff(Node root, int k, ref int diff, ref int key)
{
if (root == null) return;
if (root.data == k){
key == k;
return;
}
if (diff > Math.abs(root.data-k))
{
   diff = Math.abs(root.data -k);
   key = k;
}
if (k <root.data)
     diff = GetMinDiff(root.left, k, ref diff, ref key);
else
     diff = GetMinDiff(root.right, k, ref diff, ref key);
}
The same works for the furthest element from a given value in the same binary search tree with a modification to the comparision of the diff.
In this case, we are trying to maxinize the difference.