Data Structures Tutorial

Data Structures Tutorial Asymptotic Notation Structure and Union Array Data Structure Linked list Data Structure Type of Linked list Advantages and Disadvantages of linked list Queue Data Structure Implementation of Queue Stack Data Structure Implementation of Stack Sorting Insertion sort Quick sort Selection sort Heap sort Merge sort Bucket sort Count sort Radix sort Shell sort Tree Traversal of the binary tree Binary search tree Graph Spanning tree Linear Search Binary Search Hashing Collision Resolution Techniques

Misc Topic:

Priority Queue in Data Structure Deque in Data Structure Difference Between Linear And Non Linear Data Structures Queue Operations In Data Structure About Data Structures Data Structures Algorithms Types of Data Structures Big O Notations Introduction to Arrays Introduction to 1D-Arrays Operations on 1D-Arrays Introduction to 2D-Arrays Operations on 2D-Arrays Strings in Data Structures String Operations Application of 2D array Bubble Sort Insertion Sort Sorting Algorithms What is DFS Algorithm What Is Graph Data Structure What is the difference between Tree and Graph What is the difference between DFS and BFS Bucket Sort Dijkstra’s vs Bellman-Ford Algorithm Linear Queue Data Structure in C Stack Using Array Stack Using Linked List Recursion in Fibonacci Stack vs Array What is Skewed Binary Tree Primitive Data Structure in C Dynamic memory allocation of structure in C Application of Stack in Data Structures Binary Tree in Data Structures Heap Data Structure Recursion - Factorial and Fibonacci What is B tree what is B+ tree Huffman tree in Data Structures Insertion Sort vs Bubble Sort Adding one to the number represented an array of digits Bitwise Operators and their Important Tricks Blowfish algorithm Bubble Sort vs Selection Sort Hashing and its Applications Heap Sort vs Merge Sort Insertion Sort vs Selection Sort Merge Conflicts and ways to handle them Difference between Stack and Queue AVL tree in data structure c++ Bubble sort algorithm using Javascript Buffer overflow attack with examples Find out the area between two concentric circles Lowest common ancestor in a binary search tree Number of visible boxes putting one inside another Program to calculate the area of the circumcircle of an equilateral triangle Red-black Tree in Data Structures Strictly binary tree in Data Structures 2-3 Trees and Basic Operations on them Asynchronous advantage actor-critic (A3C) Algorithm Bubble Sort vs Heap Sort Digital Search Tree in Data Structures Minimum Spanning Tree Permutation Sort or Bogo Sort Quick Sort vs Merge Sort Boruvkas algorithm Bubble Sort vs Quick Sort Common Operations on various Data Structures Detect and Remove Loop in a Linked List How to Start Learning DSA Print kth least significant bit number Why is Binary Heap Preferred over BST for Priority Queue Bin Packing Problem Binary Tree Inorder Traversal Burning binary tree Equal Sum What is a Threaded Binary Tree? What is a full Binary Tree? Bubble Sort vs Merge Sort B+ Tree Program in Q language Deletion Operation from A B Tree Deletion Operation of the binary search tree in C++ language Does Overloading Work with Inheritance Balanced Binary Tree Binary tree deletion Binary tree insertion Cocktail Sort Comb Sort FIFO approach Operations of B Tree in C++ Language Recaman’s Sequence Tim Sort Understanding Data Processing Applications of trees in data structures Binary Tree Implementation Using Arrays Convert a Binary Tree into a Binary Search Tree Create a binary search tree Horizontal and Vertical Scaling Invert binary tree LCA of binary tree Linked List Representation of Binary Tree Optimal binary search tree in DSA Serialize and Deserialize a Binary Tree Tree terminology in Data structures Vertical Order Traversal of Binary Tree What is a Height-Balanced Tree in Data Structure Convert binary tree to a doubly linked list Fundamental of Algorithms Introduction and Implementation of Bloom Filter Optimal binary search tree using dynamic programming Right side view of binary tree Symmetric binary tree Trim a binary search tree What is a Sparse Matrix in Data Structure What is a Tree in Terms of a Graph What is the Use of Segment Trees in Data Structure What Should We Learn First Trees or Graphs in Data Structures All About Minimum Cost Spanning Trees in Data Structure Convert Binary Tree into a Threaded Binary Tree Difference between Structured and Object-Oriented Analysis FLEX (Fast Lexical Analyzer Generator) Object-Oriented Analysis and Design Sum of Nodes in a Binary Tree What are the types of Trees in Data Structure What is a 2-3 Tree in Data Structure What is a Spanning Tree in Data Structure What is an AVL Tree in Data Structure Given a Binary Tree, Check if it's balanced B Tree in Data Structure Convert Sorted List to Binary Search Tree Flattening a Linked List Given a Perfect Binary Tree, Reverse Alternate Levels Left View of Binary Tree What are Forest Trees in Data Structure Compare Balanced Binary Tree and Complete Binary Tree Diameter of a Binary Tree Given a Binary Tree Check the Zig Zag Traversal Given a Binary Tree Print the Shortest Path Given a Binary Tree Return All Root To Leaf Paths Given a Binary Tree Swap Nodes at K Height Given a Binary Tree Find Its Minimum Depth Given a Binary Tree Print the Pre Order Traversal in Recursive Given a Generate all Structurally Unique Binary Search Trees Perfect Binary Tree Threaded Binary Trees

Horizontal and Vertical Scaling

Being a software engineer, you would have designed a website or application and deployed it on any server. Imagine that the developed application starts getting popular, and many users engage with it daily. Everything seems perfect, but as the traffic increases, you realize that the server or machine you used while designing your system would no longer be able to handle all these requests and may stop responding anytime; hence the application would crash. At such times you need to do something to increase the scale of your system to handle such enormous requests at once.

To expand the scale, you need to upgrade your system's current configuration or add additional hardware devices. This process is known as Scaling.

Any developer working for any firm or organization may encounter this situation and would be expected to find an optimal solution for the same; therefore, many questions on the concept of Scaling are commonly asked in various technical interviews.

The Process of Scaling the database in your system can be done by using any one of the two approaches, namely:

  • Vertical Scaling
  • Horizontal Scaling

Let us now discuss the concept, advantages and disadvantages of both types of scaling individually:

Vertical Scaling

It is commonly known as the 'scale-up' approach. The concept of Vertical Scaling deals with upgrading the same machine or moving to a newer machine with higher specifications so that it would now be able to handle the increased traffic on the website or application. One can update their devices by embedding some additional RAM storage or adding some other features to enhance the overall performance of your application.

In simpler terms, Vertical Scaling can be done easily by switching the servers with the better versions.

Even though this approach needs not manipulate the code, it has several drawbacks.

Let us discuss some more critical points of this approach 

  1. Does not need to manipulate the code or partition the database as the ability of the existing single node to handle the traffic is increased.
  2. Implementation is easier.
  3. Lesser requirements for the workforce, as only one system, is managed.
  4. Since there is no change in the hardware, Compatibility remains undisturbed.
  5. The Vertical Scaling approach is commonly preferred by Small to mid-size firms or organizations.
  6. Example: MySQL and Amazon RDS.

Limitations of Vertical Scaling

  1. Reduces the possibility of improving the network or disk input and outputs.
  2. The extent of Scaling is limited.
  3. Replacement of the machine or server takes time and creates a halt in the working of your system.
  4. Vertical Scaling increases the risk of hardware failure.
  5. The complete procedure is expensive.
  6. Upgrading the system after vertical scaling is complicated.

Horizontal Scaling

Horizontal Scaling is also known as the 'Scale-out' approach. This is the widely used approach for systems with higher requirements for being highly available or failover. In the technique of Horizontal Scaling, we upgrade the system by parallel adding more machines or servers. This helps to divide the workload of processing or storage across multiple devices, enhancing the whole system's performance. In this approach, we directly add more instances of the machines with a similar configuration to the existing pool or network of the servers. The current server configuration remains unchanged. Also, unlike the vertical Scaling, this does not stop the working of our system while we add the new servers. The Horizontal Scaling approach is quite famous among various organizations as this technique increases the input-output concurrency, as well as the load at each existing node, is reduced. Horizontal Scaling also increases the disk capacity of the system as there are comparatively more systems.

Let us look at some of the key points of this approach,

  1. The horizontal Scalability of a system can be easily acquired by implementing the distributed file system, clustering and load-balancing.
  2. The User Traffic on the system can be effectively managed using this approach.
  3. In this approach, the Fault Tolerance of the system can be easily checked.
  4. Upgradation is simple.
  5. No downtime while adding the machine or server hence continuous and instant availability.
  6. Increasing or reducing the size per the system's needs is more effortless.
  7. Overall implementation is cheaper as compared to the 'Scale-up' approach.
  8. Large IT companies like Google, Yahoo, eBay, Amazon, etc., prefer Horizontal Scaling.
  9. Example: Cassandra and MongoDB.

Limitations of Horizontal Scaling 

  1. Designing an architecture model for implementing Horizontal Scaling in a system is a complicated task.
  2. Licensing Fees are high.
  3. Cooling expenses and electricity bills are expensive as multiple machines are used
  4. Integrating various devices into a single network requires different switches and routers.

Differences between Horizontal Scaling and Vertical Scaling

As we understand the basic principle behind both these approaches now, let us look at some of the fundamental differences between them.

TermsHorizontal Scaling              Vertical Scaling   
Load Balancing  Horizontal Scaling needs load balancing to manage and divide the data across all the connected servers in your system.While in the vertical Scaling approach, there is only one machine to handle the total traffic, so no load balancers are required.
Failure Resilience  Horizontal Scaling is more immune to system failure, as with several machines, if any of them crashes for some reason; the other servers in the network handle the user traffic and prevent the system failure.  In Vertical Scaling, there is only one machine: the single point of the crash, and hence it is much more prone to System failure. In simple words, availability in the vertical approach is higher than in the vertical scaling approach as the database runs on a single machine. When it crashes, the complete system fails.  
Machine Communication  The horizontal Scaling approach uses a network of various servers or machines with distributed data and user traffic. Hence it requires network communication, and the calls over the network are time-consuming and are prone to failure.While in vertical Scaling, the transmission over a network does not exist as there is only one machine, and it works on the inter-process communication, which is comparatively much faster.  
Data Consistency  In the Horizontal Scalingapproach, total requests are divided across various systems. Different servers deal with different demands and handle or store additional data at different locations; hence, syncing the complete data together is impossible.In vertical Scaling, all the requests are handled by a single machine and all the data is stored in the same place, so inconsistency does not occur.  

Drawbacks or Limitations

According to your budget or space, you can add as many machines as you need at a particular time in the horizontal scaling approach to scale up the complete system, but this is not the case in the vertical scaling approach; there is a limit for upgrading the machine. After reaching the limit, there is no way to increase it without further downtime.

Choosing the Approach for Your Application

Until now, we have seen the basic idea behind the implementation of approaches, their pros and cons and some of the fundamental differences between them. The main problem arises when the developer decides which method is best suited for their application or system. This is a tricky task and confusing too. The developer must take an intelligent decision here. Firstly, you should get a complete blueprint of your application's present and future requirements, as well as focus on the goals for the system and keep in mind where you would wish to add value. This critical decision should only be taken after focusing on these factors:

  1. Performance characteristics and requirements.
  2. Required Response Time.
  3. Expected requirement for system availability.
  4. Degree of Fault tolerance of your system.
  5. Reliability level of the design.
  6. Clear Understanding of both the approaches
  7. Level of data consistency needed.
  8. Throughput of your application.
  9. Short and Long-term Scalability Goals.

All of these factors would help you better understand your system's requirements and business goals. Apart from your choice, you should check whether the upgraded model would be compatible with your needs. You can choose a vertical or horizontal approach per your needs or even both in any cloud environment to enhance the performance of your application.

A common question is which of these approaches is usually used by large tech companies. The answer to this is 'Both'. The experienced teams at such companies use their excellent qualities and follow the hybrid approach to combine the speed and consistency of vertical scaling with crash resistance and infinite scalability property of Horizontal Scaling.

Keeping in mind the requirements and all these points, you can design a suitable model for your system.