As some of Python community here in Czech Republic know there was held programming contest called Wood Coding Challenge  organized by Wood & Company. The task was to create stock exchange using Python / C / C++ that runs on TCP sockets communicate by JSON messages and presents solid engineering abilities. You can find whole description of task at the website of  the contest.

This certainly had my attention and during two months I completed this challenge. I spent 50 hours of my evenings to code this up. I chose to write it in Python 3.5 using Asyncio as it was preferred library used by organizers. I learned a lot of Asyncio and it seems to be right tool to write asynchronous code.

I finished the basic task and was thinking about how to make it better. I could add more features but that looked too much like regular work and I wanted to play with this application. Therefore, I decided to do it as much scalable as I could. I wanted to run it in multiple processes even on multiple machines and thus I needed some sort of shared memory for most fundamental structure of application: Limit order book. Limit order book is a container of all orders. Most called operation is get first order under price-time priority. Second thing I needed from my shared memory was to ensure communication between each server as they need to notify clients about performed trades. To handle both these requirements I chose Redis which is fast, in-memory, data structure store that have many great feature but I used only sorted sets for Limit order book and Pub/Sub for server communication.

multiple server architecture

Multiple server architecture.

The code works quite well but it was not tested in what you could think of as production environment so I believe there is still a lot work before it could be deployed. However, it was thought of as prototype and toy application since start and I took it as that. You can find the code at my Github.

I was pleased that they pick my application to the final round where 6 of 31 contestants presented their application. I was really surprised by quality of code of all other finalists. It was quite nice meeting. Everybody introduced themselves and their code, speaking about architecture decisions we had to take. You can find my presentation in czech here. I heard a lot interesting thoughts during presentations and also during breaks.

But the best thing of all this contest was that they picked my application as a winning entry. I was really surprised because all finalists had something more over basic in their code which I neglected and few knew a lot more about the topic than I did.

Anyway I wanted to thank organizers for the contest, all other finalists for inspirational day and that the panel took my application is winning. This contest has really teached me a lot, I could meet great people and it was fun whole time.