Understanding Golang and Goroutines
Let’s start with the basics
--
This article is focussed on understanding the basics of Golang. We will talk about the performance aspect of Golang and we will try to scale up the application by creating simple Goroutines.
We will also focus on underlying execution logic and what makes Golang different from other languages.
Concurrency in Golang
Before we proceed with the article, we need to understand the concept of parallelism and concurrency. Golang is capable of bringing both concurrency and parallelism to the application.
Let's understand the basic difference.
Understanding Concurrency
Concurrency means that the application has more than one thing to do at the same time. It's about creating multiple processes executing independently.
Applications might be dealing with lots of processes together to accomplish the intended behavior. Let's assume a simple ecommerce website and evaluate the list of concurrent tasks that it needs to execute:
- Running a banner on the top with the latest deals and products.
- Display the count of currently online users of the website.
- Update the user cart details when products are selected.
- Keeping the time counter for the next “Big Billion Sale” and so on.
The ecommerce website needs to have all these tasks running at the same time to keep the customer engaged with the application and make the website attractive to the user and draw more business.
So, a simple application/website could be a set of multiple tasks running in the background to satisfy the business requirement.
In both illustrations above, we have multiple tasks getting executed at the same time, but there is still a difference between the executions. Let’s look into this further to understand it in more detail.