Building a non-trivial online service and running it on a docker cluster - my ramblings


Image result for digital ocean


I'm building an online service targeted toward realtors. It's been something I've been working on, on and off, for about 9 months now, squeezing in development when I can while juggling the numerous contracting jobs I do for various clients of my small company.

While working on other peoples projects is interesting and varied, I've always wanted to build a product for myself, and to be my own client essentially - not beholden to the random whims of others. To that end comes this system - a joint venture between my own company and that of a friends. They have the realty connections and know-how and I have the technical skills (20+ years) so between us we hope to build a product that will not only be good for our customers but also be something we can be proud of and that will pay the bills for years to come.

Being a total architecture nerd, and having worked on the this space before for my clients, our product (I wont go into details about what it *does* per say) is microservice based, and i've opted to run everything using docker swarm, on a small cluster of droplets on Digital Ocean - a first time user of this cloud provider, but so far very impressed.

I was originally going to run everything on AWS ECS, using RDS, S3 etc - but the costs kept ramping up and this is a self-funded venture, so keeping costs down is paramount. This product could potentially be in production for a year or so before it starts taking in any money from anyone! So it has to be inexpensive enough to not bankrupt us while it's getting off the ground. We did discuss getting some funding so I could work on this fulltime, but it's too risky - i'm not 20 and single - i have a family to think of, and there is no guarantee that this venture will be successful - you know how online stuff is - you will fail a number of times before you might succeed.

So, costs - on DO i can run a tiny 2 node swarm cluster for $10 USD, with a separate droplet running MySQL and a DO load balancer - so thats another $5 USD and $20 USD respectively - for a total cost of $35 a month. Its good enough to handle the load during development - and probably will be more than enough for the first few months once we go live and start on-boarding customers.

This being a microservice architecture, each microservice is deployed as a container, with some services having multiple replicas (such as the api gateway service and the tiny nginx based image that serves up the SPA).

Docker swarm takes care of being able to load balance between replicas for inter-service calls.

I stuck an LB infront of my 2 node cluster to load balance external traffic across them, and then have 2 HAProxy containers ("global" deployment - ie. one container per node) so I can perform host header based load balancing to the various web apps and web services that unfortunately the DO LB can't do because it's only able to do basic load balancing between droplets, but not at the application level.

I did think about running the mysql instance as a container also - and getting group replication setup across all the cluster nodes, but opted for a simpler dedicated droplet running mysql directly just to get things going - perhaps later once the system is up and running with all of the features built and some real world traffic pumping through it.

Each microservice is being developed using language/framework that makes sense for what it does and for ease of development - the core of the product, the bit that offers 90% of the IP is being written in scala, using the full Akka stack of libraries - actors, streams. API gateways are written in Flask-Restful using python 3.7. I'm primarily a java/scala/c# guy so probably >70% of microservices will be written in those languages, but I have dabbled in python before (django) and its a good fit for some of the smaller stuff IMO where i just want something really small and lightweight to do some simple things.

Well, thats it for now - i'll elaborate on some more bits as and when I get the time.

Comments