# Demystify Graph Coloring Algorithms

## Solve edge coloring, map coloring, and other fun problems

Graph coloring is a problem where certain colors are assigned to a particular constraint in a graph. For instance, it could be that you must color a graph, either vertices or edges, so that no two identical colors are adjacent to each other — no two adjacent vertices or edges will have the same color.

I stumbled upon this algorithm and I was thinking about what its purpose was. As I look more deeply into graph coloring problems and their use cases, I realized that they’re widely used in the applications we use. …

# Create Stack-Safe Recursion Using Trampolines in Scala

## Avoid stack overflows in your function calls

Recursion is often used when we want to compute combination values and other iterative values. Having a recursion in your function can decrease the amount of code that you write in your function. However, a lot of the time, recursive calls can be hard to deal with when you have extensive input.

Let’s look at the following example of calling Fibonacci:

In a regular recursive call, we can optimize the value by making it tail-recursive. Usually, in Scala, the annotation `@tailRec` tells the compiler to static check if the current function that you wrote is tail-recursive or not.

The problem with this is that tail-recursive is, sometimes, hard to construct, and some functions with just regular code cannot complete tail recursion. Consider creating Fibonacci in a tail-recursive manner. …

# To build a Robust System — You need to Design your System Pessimistically

When it comes to how we view the world, most of us fall into one of the two types: Optimistic or Pessimistic. Whether you are one or the other, scientists said it has to do with our upbringing and culture. There are both pros and cons in viewing the world one or another.

An optimistic view of things makes one willing to try new things. Usually, optimistic thinking equals positive thinking. If you are confident and hopeful that the project you initiate will have a brighter future, you will be more likely to start that project. …

# The Ultimate Mind Shift for Building Grid

As the new year starts, I need to finish some stuff on last year’s task. One of the studies is to finish reading Steven Pressfield, The War Of Art, a must-read book for anyone trying to fight with their inner resistance.

One of the key concepts in the book is working hierarchically vs. territorially. It is such great insights for changing our way of thinking towards the work we do that I would like to share in this article.

“In the animal kingdom, individuals define themselves in one of two ways — by their rank with hierarchy (a hen in a pecking order, a wolf pack) or by their connection to a territory (a home base, a hunting ground, a turf). This is how individuals — humans, as well as animals — achieve psychological security. They know where they stand. …

# How do you create an Efficient Data Structure for Spatial Indexing?

Data structure helps us store values within our data and help us efficiently do the operation with those data if we need them. For instance, if we want to store 1-dimensional data points, natural numbers that you will plot in a single line or a string, we can use a 1D array to store these data. To create a fast retrieval (search), we will use a natural order indexing (1 < 2 < 3) or using a data structure like Trie or Binary Tree.

What if we want to work with the 2D space and store our data to do a fast retrieval? What if we’re going to find proximity ordering, such as find all the nearby points that are close to this point? …

# System Design: How Do you Generate an Incremental Global Unique in a Distributed System?

Have you ever wonder how you can implement `getUUID`? We often set random IDs for making an entry in a table. The most common way is to create a `UUID.randomUUID`. However, many programming languages and cloud infrastructure have provided us with UUID that sometimes we took the function for granted.

# What is a globally unique identifier?

A globally unique identifier is a function that will generate a different output each time you call that function. It will not create the same function on the same machine, another machine, or even your lifetime. It needs to be unique.

In this article, I would like to walk through the thought process of creating an incrementing globally unique identifier. …

# How Should We Determine the Ordering of Our Microservices?

## A look at strategies when thinking about distributed systems and microservices

Microservice architecture can help teams develop applications asynchronously. Teams can deploy their code base, creating a faster iteration and development process overall. However, with flexibility, there also comes complexity in developing distributed systems. Many of our assumptions in a single system don’t work in a distributed system, and we need to reevaluate how we approach our design in distributed systems.

One example of this is time ordering. I recently wondered how you can ensure the services you created are in the right order.

Imagine you created an event-driven architecture with two microservices: a Product service and Order service.

The Product service will be responsible for managing products, and Order services are reliable for managing orders. The Product service can emit a `CreateEvent` and `UpdateEvent`, and based on the event, the Order service consumes the messages through a queue and updates its local data store. …

# Patterns for Constructing Stateful Programs without Any Mutation

When developing an application, it is often useful to have some state in the application to detect the current point at which the program is executed. Often, we want to operate in sequential data streams, such as the parser, firewalls, communication protocol, or a stream of data. In some of these operations, the previously computed data is stored in some variable (State) and will often influence the program’s current execution decisions.

We can call these operations a stateful operation, where the program’s previous execution is carried over to the current implementation. …

# Create a Throttling System for Any Application with no more than 100 lines of Code

Applications are often design with a throttling mechanism involved. Sometimes, we want to limit the number of requests to improve our application’s security and performance. Sometimes your application cannot respond to more than a certain number of connections. For instance, if you polled the message as fast as your can from a queue and did not limit the number of connection, your application will soon exhaust its connection fool and face Denial of Service error. …

# How to Write Data to a File with FS2

Last week, I tried to investigate raw data from Dead Letter Queue (DLQ) at work. One of the functionalities that I want to do is poll sources from the SQS DLQ and write those data in a file for further investigation. I thought using FS2 will be a great use-case for this.

FS2 is a light-weight streaming library that can help you do a lot of data processing functionality. Often, we want to get some data from upstream and write them to a file for any investigation.

I want to share how we can create a simple type class for writing data to a file system with FS2. …