From the Zero Penny Series

The Zero Penny Architecture explained

Creating a complete environment composing only free products

Alessandro Sanino
9 min readJul 21, 2019

EDIT: Thank you for all your support. Due to the received feedback I wrote another article adding other free tools in the Zero Penny Architecture at no cost, de facto extending the architecture itself.
You can find it
HERE, stay tuned for more.

Greetings web traveller,

I always had the problem to create cloud architectures when I wanted to create cool applications. If you are like me, you:

  • Are a developer, with Cloud Engineering background
  • Are a curious person who develops a lot of things on its own
  • Usually have no money to setup a development architecture for your projects
  • You want for your architecture to be easily migrable to something more powerful if your startup gets sufficient investment, but you just donā€™t want to spend money only for a development/staging cloud environment
  • Optionally, you come from Piedmont, a region in the north of Italy, famous for its inhabitants never happy to give money for services (in fact, you can refer to this model also with the name Piemontish Architecture Model or PAM šŸ˜‚).

Based on these assumptions, I created a collection of services without spending a single penny and I reached all the scalability objectives for a small to medium project.

And now I am going to explain you how to replicate and do it for your project.

Warmup

We are going to cover what are in my honest opinion the components you need to develop your architecture first, and later attach them each other. The basics components are:

  • A git server: You are going to need this to store your code in multiple repositories and work with your team concurrently without issues
  • A Continuous Integration service: This is used to automatically build and deploy your application to remote servers, check your code when you are doing a PR, and notify all involved people when something important related to code is happening
  • A Container Engine who can run your software on remote hosts. An example of this services is docker
  • A VPS or equivalent host who can run Containerized Applications
  • A CDN to serve static content at the speed of light: you usually use Content Delivery Network to distribute the load of static assets for better delivery speed, due to their caching.

For each one of this components, we must choose a free solution that can interoperate with the others, letā€™s see how itā€™s done.

Git service: Gitlab

Gitlab is a software which can come in two modes:

  • Cloud mode is hosted on gitlab.com and allows you to have unlimited private repositories for teams up to 5 people
  • Self-Hosted mode is hosted on your servers and allows you to have full control of the gitlab environment at no cost

NOTE: we are referring to Gitlab Community Edition, other editions have costs you should consider if you want extra services.

Continuous Integration: Gitlab again

Yes, Gitlab comes with an extra feature called Gitlab runners. You can use them to run Continuous Integration pipelines over your code to do deploy, notify and check tasks on commits and pull requests over code stored in gitlab repositories.

Again, we have two options:

  • Host your own Gitlab runners for free in your servers (even localhost) and use them without limits.
  • Use Gitlab set of public shared runners on the cloud and get 2000 build minutes for free per month. This is a good head start if you donā€™t have free VPS to start your runners into.

Container Platform: Heroku PaaS

Heroku is usually not used as pure VPS but allows (using the container heroku stack) to deploy docker containers and use them on heroku dynos for free for up to 10000 dyno hours per month/account.

Again, this is an awesome start because it allows to deploy apps for free.

It also binds easily with the so-called Heroku addons, which allow to integrate databases, monitoring services, etcā€¦ with just a click of a button.

NOTE: Please check the dyno limits to see what are free dynos limits.

There is a problem in this, though: if Heroku web processes (which usually correspond to deployed applications) do not receive HTTP requests in 30 minutes are made sleeping by Heroku itself.

This is good because it allows you to save dyno hours, bad because on next restart you will need to wait for dyno coming back serving requests.

This is generally not true for worker and one-off processes. See Heroku Dev Center for details and explanations.

We are going to use Heroku Container service to deploy via Gitlab our application, but first letā€™s see how to attach plugins to our our newly created heroku app.

CDN and DNS: Cloudflare

NOTE: this step is optional and works only if you bought a domain, you can buy cheap domains directly on cloudflare website or namecheap.com

Cloudflare is a cloud service whch has multiple features, and different payment plans. On free plan it allows you to have free CDN, DNS and anti DDoS.

If you setup a cloudflare account and migrate the nameservers to their configuration, you will be able to leverage cloudflare caching on your application almost seamlessly.

A case study: the Tryvium Booking Platform

At The Tryvium Company LTD we want to provide best travel experience to all travelers and hotel managers around the world. Thanks to blockchain technology we are able to cut costs and intermediaries, resulting in lower prices.

We are developing a complete suite of software to benefit all the actors in the ecosystem:

  • Booking Platform to serve travellers, allowing them to book hotels and make reservations using crypto and fiat
  • Tryvium All-In-One software to provide the hotel managers all the tools they need to manage their company from all points of view
  • Tryvium Gift Experience to tokenize gift boxes travelers can use to choose between multiple predefined locations

The case study here is the development of the Booking Platform part, where we created the entire development ecosystem using the already cited components:

The full set of components together in a single architecture

To create this, we need to:

  • Connect Gitlab and Heroku
  • Install heroku addons for postgres and redis
  • Bind Cloudflare and Heroku to allow caching

Gitlab ā¤Œā¤ Heroku

To connect gitlab with heroku we need to perform some initial assumptions:

  • you registered an account on gitlab.com and heroku.com
  • you know how to write a gitlab pipeline (see here for additional info)
  • you know how to write a Dockerfile
  • you created an empty heroku application from heroku.com website

To deploy to heroku from a gitlab pipeline you can use the following example job as inspiration to put yours in the .gitlab-ci.yml file of your project:

variables:
APP_NAME: "YOUR_HEROKU_APP_NAME"
stages:
- Build Artifacts
- Deploy
# Add some job in "Build Artifacts" stage to prepare the artifacts to push along with the docker image.Deploy to Heroku:
stage: Deploy
image: docker:stable
services:
- docker:dind
only:
- develop
- master
when: manual
script:
- docker login -u _ -p $HEROKU_API_KEY registry.heroku.com
- docker build -t registry.heroku.com/$APP_NAME/web .
- docker push registry.heroku.com/$APP_NAME/web
- docker run -e HEROKU_API_KEY=$HEROKU_API_KEY wingrunr21/alpine-heroku-cli:latest container:release web -a $APP_NAME

As you can see there are some important things to notice:

  • There is a pipeline variable called APP_NAME which is used to identify your application and must correspond to the name of the heroku app you just created.
  • There is an environment variable called HEROKU_API_KEY which is injected into your pipeline, to retrieve it just go to your heroku account settings and you will find it. After that, you must set it up as repository or group variable in your Gitlab.
  • The heroku cli is used in the form of docker image, to achieve this the wingrunr21/alpine-heroku-cli is used and executes the push to heroku using the Dockerfile you created in the root directory of your project, creating a web process.
  • The gitlab pipeline is executed in a docker container, therefore to work with docker a special service called dind (AKA Docker in Docker) is used to allow the deploy.

After doing that you will see that your heroku application will successfully deployed after a manual trigger on merge requests involving develop and master branches on your repository.

Letā€™s now connect heroku and cloudflare.

Heroku ā¤Œā¤ Cloudflare

To serve an heroku application using cloudflare we assume the following:

  • You created an heroku account and deployed your application.
    For convenience, we assume your app name is myapplication , reachable at https://myapplication.herokuapp.com. We also assume that the application runs on a web heroku process.
  • You bought a domain. For simplicity we assume it to be mydomain.com in the explanation.
  • You already moved your nameservers to cloudflare and DNS is properly working.

To connect cloudflare to an heroku application, you must do the following:

  • Go to your heroku application settings, reachable at https://dashboard.heroku.com/apps/myapplication/settings
  • Differently form what said on the Heroku documentation, which says to point your DNS to heroku, just click on the Add domain button under the ā€œDomains and certificatesā€ section and add mydomain.com.

After that you will see your domain on the list. Letā€™s now configure cloudflare.

  • Go to cloudflare and go to your domain settings (you can find them at https://dash.cloudflare.com/your-session-hash/mydomain.com/dns) and select DNS tab.
  • Add a new CNAME record like in the following image
NOTE: in this picture we use @ (root address) as address, but you can put any subdomain of your choice

The record to put is CNAME type because heroku does not provide a static ip.

Attaching PostgreSQL and Redis

Heroku addons are particular plugins which enable to run parallel services attached to our heroku application. You can explore them in the heroku add-on repository.

For our case study we are going to attach a PostgresSQL and a Redis cluster, both available for free.

Here the link for the addons:

To attach an addon to our application we must do the following:

After clicking on Submit Order Form the addon will be enabled for your app

  • Perform the same process with Heroku Redis addon and you will complete the setup
  • Refer to the environment variables generated on your Heroku Application in your code and you will be able to contact the services provided by the addons. In particular Heroku Postgres creates an environment variable called DATABASE_URL and Heroku Redis creates another one called REDIS_URL.

Wrapping things up

As you have seen in this article, you can get up and running a complete professional architecture for your applications without spending money by composing services available for free.

The most interesting fact is that gitlab can serve multiple repositories and heroku can host multiple apps (up to their respective limits for the free tier) so you can host multiple projects by leveraging this as unique DevOps architecture.

Appendix: Useful links

Heroku website: heroku.com
Cloudflare website: cloudflare.com
Gitlab website: gitlab.com
Heroku CLI in docker: hub.docker.com/r/wingrunr21/alpine-heroku-cli
Tryvium website: tryvium.io

I hope you found this article pretty useful. If this helped you in any way, consider following me on github, or donating to the following cryptocurrency addresses:

BTC: 3PZYF93oZ4cyF5nUoD56mCmJsGEWzmDzPrETH: 0x8b48Af3a5B965F94dE7d1870bf2194c2798e4183SYS: ShmVjaK4bW2LfhbMyx253QvyDbjD1h71yx

Also do not forget to follow Tryvium on facebook, twitter, github and reddit to see the latest updates.

Tryvium has also an official Medium profile where all the development updates are written to allow people to see our progress.

Stay Awesome,

Alessandro Sanino

--

--

Alessandro Sanino

CTO at Tryvium Travels | Blockchain Researcher & Developer | Cloud Architect