Implementing mTLS in Go

development golang microservices

Introduction Mutual authentication with Transport Layer Security (mTLS) is a method for mutual authentication. It is often used in securing network communication between two services and ensures that the parties at each end of this communication are who they claim to be by verifying that they both have the correct private key. It has been a standard security and authentication mechanism in a service mesh like Istio, Linkerd, AWS App Mesh and others.

Union Find in Python

algorithms python

Introduction According to Wikipedia, dynamic connectivity structure is a data structure that dynamically maintains information about the connected components of a tree. Once the the dynamic connectivity structure is built, it should adapt itself such that it can give quick answers to queries of the form “is there a path between x and y?”. The Union-Find algorithm is one approach build this connectivity structure. There are multiple approaches the Union-Find algorithm, the most optimal approach is the Weighted Quick Union algorithm.

Background Tasks in Go

development golang workers

When you design a software system or REST API, there are times when you would want to process large amounts of data or do time consuming computations that cannot be completed within a decent amount of time. You cannot expect your users to make an HTTP call that takes several seconds or minutes to respond while the backend server handles the request by doing some time consuming task. Often the load balancer or the HTTP server will enforce a timeout for a request after which the connection is terminated and results in a gateway timeout error.

Implement tail command in Python

algorithms python

Introduction In this article, we will write a simple implementation of the tail command from Linux. This program will take a file and an integer n as input and print the last n lines from the file. Also, the goal of the program is to not read the entire file into memory at once. This will make the program memory efficient when dealing with very large files. Implementation Details In order to implement this program, we will use queue data structure.

Read More

Checksum Validation In Go

md5 sha256 checksum golang

In today’s snippet, let’s look at how to generate checksum of a string or a file in Go. A checksum is a cryptographic signature of a file or a string. It is usually used to check if a file or stream of bits has been tampered or modified. If the file is modified, the checksum for the file changes. There are various cryptographic algorithms available to generate the checksum of a file or string, the popular algorithms are md5 and sha256. Let’s look at how we can generate these checksums in Go.

Strings Concatention In Go

development golang

In today’s snippet, let’s look at how to use string builder and bytes buffer to concatenate a list of strings. You can always use the + operator to concatenate strings, but it is memory inefficient just like in so many other languages. Each time + is used to concatenate a string, it allocates a new string in memory. This is because, like in most languages, strings in Go is immutable. To avoid this inefficiency, we can use Go’s strings.Builder and bytes.Buffer type. Let’s look at how we can use these types to concatenate strings.

Ordered Printing With Goroutines In Go

development golang

In today’s snippet, let’s look at how we can use synchronization techniques in Go to print natural numbers in order from two different goroutines. In our example here, we have two goroutines; one goroutine will print even numbers while the other goroutine will print odd numbers, but the output has to be in increasing order. To implement this, we will use a channel to synchronize the printing in the two goroutines. We will also use sync.WaitGroup to wait for the goroutines to finish before exiting the code. Note that we will need an unbuffered channel so that one goroutine is blocked while the other is printing the number. The even goroutine will use the done variable to indicate to the odd goroutine that it is done with the printing and there is nothing listening to the syncChannel. Without this, you will see a deadlock at the end of the printing.

Implement a queue using two stacks in Python

algorithms python

A queue is a First-In-First-Out linear data structure, i.e., the element that is first inserted into the queue is the element that comes out first. The operation that involves inserting an element into the queue is called enqueue. The operation that involves removing an element from the queue is called dequeue. Normally, a queue is implemented using an array and two pointers; front and rear. This makes the time complexity of enqueue and dequeue operations O(1).

In this snippet, we will instead look at implementing a queue using a stack. This may increase the time complexity of the enqueue or dequeue operations, but the idea here is to see how such an implementation will look like. A stack is a Last-In-First-Out linear data structure. Here the last element inserted into the stack is the first element that comes out of the stack. It has push and pop operations where push inserts the element into the stack and pop removes the last inserted element from the stack.

Read More


Bharghava Varun Ayada is a Staff Software Engineer at Walmart Labs, living in Bangalore, India. This blog is about software engineering, system design, distributed systems and DevOps.

Github / Twitter / LinkedIn / / Stackoverflow

Recommended Books
Designing Data-Intensive Applications / Staff Engineer / Building Microservices / Site Reliability Engineering

Get new posts by email