From reduced costs to enhanced performance and reliability, using a queuing service that leverages cloud computing resources like storage, network, memory and processing capacity provides numerous benefits. However, when it comes to selecting the right queue for your application, a myriad of distinct factors, such as how much your organization can afford to spend and how much effort you’re willing to exert, need to be considered.
In this series of blog posts, we’ll delve into what a queue is and different flavors of queues, queuing service use cases, cost drivers to consider and best practices to follow when selecting a queue. This first part will tackle what a queue is and different types of queues.
What is a Queue?
Common in computer programs, queues are data structures that order a collection of items in a sequence. Queues can be modified by adding new items at one end and removing existing items from the other end of the sequence. Much like the words we use in situations in which people wait in line for goods or services, elements are traditionally added to the end of the sequence that is called the “back,” “tail” or “rear” of the queue, and the opposite end at which elements are removed is called the “head” or “front” of the queue.
In a common use case, “push” is the operational term for adding an element to the back, tail or rear of the queue, while “pop” is the operation done to remove an element from the container. Fundamentally, queues are intended to push items into the data structure and pop them out in some order, and there are different data structure orders:
- First-In-First-Out (FIFO).
- Last-In-Last-Out (LILO).
- Last-In-First-Out (LIFO).
- First-In-Last-Out (FILO).
In what are commonly known as “stacks,” or data types for collections of elements/objects that are retrieved in reverse order of their time of storage, previously stored elements cannot be retrieved until the “top” (latest) element has been retrieved. Queues, on the other hand, typically employ a FIFO data structure, which means elements are retrieved in the order of their time of storage or that the element that has been in a queue for the longest amount of time is the first one to get popped.
Additionally, there are different flavors queues can take. Let’s take a look at the three most common types of queues.
Different Types of Queues
Linear Queue or Linked Lists
Also known as an array, a linear queue is the most common type of queue. In a linear queue form, elements are able to join the queue at one end and can exit from the queue at the other end, following the FIFO structure. In the most basic implementation, linear queues work through a fixed amount of allocated memory. However, when the end of the allocated memory is reached, no additional items can be added. You can, of course, also allocate memory as you need more elements in your queue, and free that memory when you’re done. Linear queues are also known as a linked list. Linked lists are a little more complex but grant greater flexibility at the cost of CPU and memory to manage them.
Much like linear queues, the operations of circular queues, also known as circular buffers, are performed based on the FIFO principle but with the last position connected back to the first position to make the data structure, well, circular. Circular queues, unlike their linear counterparts, allow for memory to be reused. They won’t run out of memory, but you can overwrite data in the queue once you wrap around if you’re not careful. Consequently, circular queues are often more efficient in resource-constrained environments when dealing with streamed data.
Much like the name implies, priority queues are based on the order of priority of the elements in the queue, meaning each element has a different level of priority attached to it, such as high priority or low priority. In computer science, priority queues are utilized to handle the execution of processes, with the higher-priority (more important) processes getting the processor’s attention ahead of those that are less important.
Queuing Service Considerations
You should be getting the idea that there are numerous ways to implement a queue and each method has its own advantages and disadvantages. As you’d expect, the type of queue and implementation of the queue applied requires careful consideration based on the advantages and disadvantages in the context of the problem you are trying to solve.
Now that we’ve covered what queues are and the different types of queues, stay tuned for our next post in this series as we discuss different use cases and what queues are used for before tacking cost drivers to consider when choosing a queue and best practices to follow when selecting a queue in future posts.