Background Tasks in Go

Introduction 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.

Implement tail command in 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.

Ways to Rate Limit Requests in Go

Introduction Layer 7 DDoS attacks are quite common these days. With a simple script, any one can send thousands of requests to services to exhaust server resources. They can easily take down services and cause disruptions to a business. It is wise to implement strategies to mitigate such attacks using techniques that limit the number of requests a person can send to the service. It is possible to rate limit the user requests by IP address or a user ID, if available, although the former is more popular.

Strings in Go

String Types In Go, a string value is a sequence of bytes. A string value could be empty and the number of bytes is called the length of the string and is never negative. Strings are immutable: once created, it is impossible to change the contents of a string. The predeclared string type is string; it is a defined type. Normally, the length of a string s can be discovered using the built-in function len.

Vanity URL for Go packages

Introduction If you have been working with Go programming language for a while, you would have noticed that a lot of open source packages that you import start with…. You would then use go get command to download the package and add it to your go.mod file. For instance: $ go get -u What if you did not want this dependency on Github and rather wanted to host your own git server?

Microservices and cloud native development using Micro

Introduction For the past few years, Microservices has been all the rage and it has helped a lot of organizations to adopt continuous delivery and evolve its technology stack. There are quite a few programming tool kits and platforms that have sprung up to enable building Microservices. One among them is Micro, which is a cloud native development platform that addresses the key requirements for building services in the cloud.

Using Ristretto to cache objects in Go

Introduction In my previous article on Greycell, I wrote about caching objects using tags and how it can make cache invalidation easier. I used Redis as a temporary store for our objects that needed to be cached. Although Redis is really good for this, I wanted an embedded key-value store in order to avoid additional dependency of maintaining a Redis server. When I explored further, I came across many embedded key-value store like groupcache, fastcache, burrow cache and Dgraph’s Ristretto.

Validate email address in Go

When you have a website with login or subscribe option, it is always nice to validate if the provided email address is valid. I want to briefly provide a way to do this in Go here. There are multiple ways to do the validation, but here are the three steps we will use to validate an email address. Firstly, based on the RFC 3696 Errata 1690, a valid email address has a maximum of 254 characters.

Caching records by tags in Go

Caching has an important role to play in a system design. It is primarily used to speed up information retrieval from a service and reduce the load on a database engine, the primary source of truth for a service. Data that is frequently requested by users are stored in a in-memory key-value store, like Redis, to speed up subsequent look up of the same data. In this post, I want to specifically talk about cache invalidation and provide an implementation in Go for invalidating cache using tags.

Validate Tor IP Address in Go

Tor Network Tor is a free and open-source software that enables anonymous communication. It directs Internet traffic through a free, worldwide, volunteer overlay network to conceal a user’s location and usage from anyone conducting network surveillance or traffic analysis. It has helped protect the personal privacy of its users and enabled the ability to conduct confidential communication by keeping their Internet activities unmonitored. Tor protect’s a user’s privacy, but does not hide the fact that someone is using Tor.

Counting Sort in Python

Comparison Model In computer science, sorting a list of items is a very basic as well as an important problem, that is discussed in some great detail. We basically start by using some of the simplest and intuitive techinques to sort items, like Bubble sort or Insertion sort, which are not very efficient. By efficiency, I mean their runtime is very large for very large list of items. These basic algorithms have a time complexity of O(n^2).

Multipart Requests in Go

MIME and Multipart Multipurpose Internet Mail Extensions (MIME) is an internet standard that extends the format of emails to support non-ASCII character sets, messages with multipart parts and non-text attachments like images, video, binary files etc. Multipart originates from MIME and a multipart message is a list of parts. Each part contains headers and a body. The MIME standard defines various multipart messages subtypes like mixed, digest, related, form-data, byteranges, encrypted and a few others.