Sign in

Distinguished Engineer @AmericanExpress building payments systems. Author: https://amzn.to/3kuCFpz, Thoughts, & Opinions are my own.
Photo by Jose Antonio Gallego Vázquez on Unsplash

Working with TCP servers is a great way to become familiar with low-level network communications. When writing applications that communicate directly over TCP sockets a multitude of socket management steps are required. Actions that you typically don’t have to take for a typical HTTP-based application.

Sometimes, those extra management steps include having to close a TCP session forcefully.

Today’s article will discuss two ways to close TCP sessions; the traditional default close and a forceful close using the SetLinger() method. This article will also explain why these are different and when someone should use each method.

A basic TCP server in Go

The programming language we…


Photo by Sean Stratton on Unsplash
Photo by Sean Stratton on Unsplash

I was recently restructuring one of my early Go side projects. As I was changing the project layout, I was reminded there are many recommendations out there but no set standard for structuring Golang projects.

In other programming languages such as Java, there is a typical project layout that most programmers follow inherently. In Python, the framework used (i.e., Django or Flask) will define how the project is structured. However, Go is still at a point where the community hasn’t settled on a defacto standard.

There are, however, some strong recommendations, but as I was going through those recommendations, I…


Photo by Oxa Roxa on Unsplash

I see this one question pop up in channels over and over again.

“What is the best way to mock a database for unit tests?”

For most, the thought of mocking responses from a database is daunting. Taking each DB call and creating a unique mock response can be a lot of work, especially within a large service.

This article proposes an alternative idea. One that I’ve been using for both open source and enterprise applications.

Rather than spending forever creating mocks of a database. Run the database itself as part of your continuous integration (CI) pipeline. …


Photo by Eutah Mizushima on Unsplash

Note: This article is a republish of a 2012 blog post, Medium doesn’t support back dating… Forgive the dated material.

Linux has many tools available for troubleshooting; some are easy to use, some are more advanced. I/O Wait is an issue that requires advanced Linux tools and advanced usage of some of its most basic tools.

I/O Wait is difficult to troubleshoot because, by default, there are plenty of tools to tell you that your system is I/O bound and there is a problem.

But few tools can narrow the problem to a specific process or multiple processes.

Answering whether or not I/O is causing system slowness

We can…


Photo by Jametlene Reskp on Unsplash

When working with HTTP-based services in Go, many developers (including myself) like to use HTTP Multiplexers (mux). Multiplexers, also sometimes referred to as Request Routers, offer a suite of features and capabilities. The simplest form allows users to register a specific handler function with specific URL patterns and methods.

One of the more advanced features is using HTTP Multiplexers to create “HTTP middleware.” This capability allows users to create a standard function or set of executed functions before requests route to the User-defined handlers. …


Photo by Austin Lowman on Unsplash

Recently I wanted to revamp one of my side projects go-quick. This project is a boilerplate web application meant to be a starting point for Go apps. Previously, I wrote a custom config package within the project to pull configuration from Environment Variables as per the 12 Factor Apps manifest. But, I wanted to expand how users can configure my project.

Enter HashiCorp Consul. Consul is open source and solves many of the platform pain points of running modern applications. One of those is dynamic configuration via its distributed key-value store. With Consul, applications can boot up using Consul as…


Photo by Phil Hearing on Unsplash

When I was learning Golang, one of the concepts that took me the most time to grasp was Interfaces. Golang’s Interfaces are a great way to make modular and testable code. But they can also be a bit confusing at first glance.

One of the best ways I’ve found to teach how interfaces work is by creating a mock implementation of an existing Interface.

This article will cover creating an interface and creating a mock implementation for that Interface. But before we jump into a working example, we should first understand the value of Interfaces.

Why Interfaces

When thinking about Interfaces, consider…


Photo by Markus Spiske on Unsplash

Before learning Go, I used to write most of my applications in Python. When I was transitioning from Python to Go, I was familiar with parsing JSON, YAML, etc., into Python dictionaries. What I never understood is why I would see so many examples parsing JSON into Go structs. Why not use maps, which are equivalent to a Python dictionary. What were the benefits of using structs vs. maps, or were maps some secret technique that Python taught me that all these Gophers didn’t know?

The truth is, it all depends on how we use the JSON data; in some…


Photo by Marc Liu on Unsplash

This article is part of a multi-post series on Software Design. In the last post, we took our design and scaled it up to meet our unique performance needs. In this article, we will start ensuring that our platform is highly available.

As mentioned in previous articles, this application platform is by example. As we cover the design options and challenges for this application, it is essential to keep in mind that it is an example.

Understanding our Availability Needs

Much like scaling, when designing for availability, it is easy to take a simple design and make it complicated. Complexity often happens due to…


Photo by JOSHUA COLEMAN on Unsplash

This article is part of a multi-post series covering Software Design. In the previous post, we outlined a high-level architecture of our example platform. In today’s article, we are going to explore scaling that high-level architecture to meet new demands.

Since this article is “by example,” It is worth calling out that our scaling problems are fake. They will be in areas we expect. Whereas in the real world, scaling issues show up in the most unexpected ways.

For this article, we will cover scaling the architecture into what I would call the second phase of our design.

Scale when we need to

One of…

Benjamin Cane

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store