Hi, I’m Ilija 👋

Software engineer sharing learnings and realizations. Interested in platform engineering, cloud native technologies, distributed systems and DevOps. Works at Scribd.

Deep dive in CORS: History, how it works, and best practices

The error in your browser’s console No ‘Access-Control-Allow-Origin’ header is present on the requested resource. Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://example.com/ Access to fetch at ‘https://example.com’ from origin ‘http://localhost:3000’ has been blocked by CORS policy. I am sure you’ve seen one of these errors, or a variation, in your browser’s console. If you have not – don’t fret, you soon will....

April 12, 2021 · 20 min · Ilija

Testing in Go: Stop Leaking Files

No test suite is perfect. Some test suites are missing good helper functions; others are under-configured or over-customize. Some have obsolete packages included and are left unmaintained. Folks that have experience with more mature projects will likely agree that all of the above can be found in the wild. Often, when we test our Go programs, need to create files. Such files can be just fixture files, or whole file trees, to set up the correct environment for the tests to run....

May 22, 2020 · 14 min · Ilija

Four Steps to Daemonize Your Go Programs

If you have ever worked with Ruby, or have maybe maintained a Rails application, I am sure the name Sidekiq will sound familiar. For those unfamiliar with the project, Sidekiq is a job system for Ruby. It is a wildly popular project, and the author has turned it into a successful business. None of the above would be relevant if Sidekiq’s author Mike Perham, in 2014, did not write a concise and informative post titled “Don’t Daemonize your Daemons!...

May 2, 2020 · 16 min · Ilija

Understanding bytes in Go by building a TCP protocol

Some of my newsletter subscribers have asked me a few times what is the easiest way to think about byte slices, or using Go’s syntax: []byte. Folks that have experience with low-level languages, where working with bytes is widespread, usually do not have challenges comprehending what []byte means and how to use it. But, if you come from a dynamic or a high-level language background, although everything we do ends up being a bunch of bytes, higher-level languages hide such details from us....

April 2, 2020 · 28 min · Ilija

Testing in Go: WebSockets

WebSockets offer duplex communication from a non-trusted source to a server that we own across a TCP socket connection. This means that, instead of continually polling the web server for updates and having to perform the whole TCP dance with each request, we can maintain a single TCP socket connection and then send and listen to messages on said connection. In Go’s ecosystem there are few different implementations of the WebSocket protocol....

March 13, 2020 · 11 min · Ilija

Testing in Go: HTTP Servers

Go’s a great hammer for a lot of nails, one of the areas where I find it fitting is building HTTP servers. The net/http package of Go’s standard library makes it easy to attach HTTP handlers to any Go program. What I find delightful is that Go’s standard library, also has packages that make testing HTTP servers as easy as building them. Nowadays, it’s widely accepted that test coverage is important and useful....

March 2, 2020 · 11 min · Ilija

Testing in Go: Clean Tests Using t.Cleanup

Go v1.14 ships with improvements across different aspects of the language. Two of them are brand new t.Cleanup, and b.Cleanup methods, added to the testing package. The introduction of these methods will make it easier for our tests to clean up after themselves. This was always achievable through the careful composition of (sub)tests and helper functions, but since Go 1.14, the testing package will ship with one right way to do that....

February 18, 2020 · 11 min · Ilija

Testing in Go: Golden Files

Hardcoding the expected values in an assertion is a straightforward approach in testing. Most of the time, we know the expected output of the unit under test, so simply adding the raw value to the assertion works well. Things can get tricky when we are testing a unit whose output is cumbersome to hardcode. The straightforward remedy is to extract this cumbersome value to a file that we can then read and compare the output of the unit under test to the output of the file....

February 2, 2020 · 16 min · Ilija

Make resilient Go net/http servers using timeouts, deadlines and context cancellation

When it comes to timeouts, there are two types of people: those who know how tricky they can be, and those who are yet to find out. As tricky as they are, timeouts are a reality in the connected world we live in. As I am writing this, on the other side of the table, two persons are typing on their smartphones, probably chatting to people very far from them. All made possible because of networks....

January 5, 2020 · 15 min · Ilija

Testing in Go: Test Doubles by Example

One of the biggest misconceptions is that doubles are a specific implementation of mocks or other testing constructs that we use in testing. Dummies, mocks, stubs, fakes, and spies ARE test doubles. Test double is the category of these test constructs. Over the years, there has been some confusion around this concept. It is my observation that this confusion arises from the naming of testing constructs that the popular testing frameworks use....

December 16, 2019 · 9 min · Ilija