Code Vigorous

Dustin J. Mitchell

Chapter in 500 Lines or Less

17 Jul 2016

I wrote a chapter in the latest book in the “Architecture of Open Source Applications”, “500 Lines or Less”.

The theme of the book is to look in detail at the decisions software engineers make “in the small”. This isn’t about large-scale system design, community management, or working on huge codebases (like, say, Firefox). Nor is it about the design and implementation of “classic” computer science algorithms that a student might learn in school. The focus is in the middle ground: given a single real-world problem, how do we approach solving it and implementing the solution in an elegant, instructive form?

My chapter is on distributed consensus. I chose the topic because I was not already familiar with it, and I felt that I might produce a more instructive result if I experienced the struggles of solving a novel problem first-hand. Indeed, distributed consensus delivered! Building on some basic, published algorithms, I worked to build a practical library to provide distributed state to an application. In the process, I ran into issues from data structure aliasing to livelock (Paxos promises not to reach more than one different decisions. It does not promise to reach more than zero!)

The line limit (500 lines) was an interesting constraint. Many of my attempts to work around fundmantal issues in distributed consensus, such as detecting failed nodes, quickly ran hundreds of lines too long. Where in a professional setting I might have produced a library of many thousands of lines and great complexity. Instead, I produced a simple, instructive implementation with some well-understood limitations.

The entire book is available for reading online, or you can buy a PDF or printed copy. All proceeds go to charity, so please do consider buying, but at any rate please have a look and let me know what you think!

I haven’t yet read the other chapters, aside from a few early drafts. My copy is being printed, and once it arrives I’ll enjoy reading the remainder of the book.