Building Infrastructure for Blockchain with Terraform and Chef on AWS

0
3532

Introduction

In this article we will discuss the infrastructure and requirements that are necessary for blockchain-based products. We will also provide some possible solutions for an infrastructure as code or Devops approach using Amazon Web Services, Chef and Terraform by Hashicorp.

See the source code here:

https://github.com/conor123/blockchain-infrastructure

Use Case

Our use case is an application with a database, web server and miner. This will allow us to have a basic mining node, a web interface layer, api and database.

Requirements

Blockchain products already run the full gamut of technologies. We will begin by examining the common use case scenario with the aim of further understanding how best to design and implement a viable solution.

Let’s consider the following general areas to be central to a successful solution:

  • Security
  • Scalability
  • Stability/Reliability
  • Backend Processing
  • Front End Systems/User Interfaces
  • Data Analytics

Security

We will create a secure infrastructure as follows:

  • Virtual Private Cloud
  • public and private subnets and
  • security rules to restrict traffic on ports
  • ssh access
  • AWS IAM User with ID and secret key

Scalability

AWS infrastructure allows for Autoscaling groups – to be added in a later feature.

Stability & Reliability

The AWS Infrastructure is Stable and Reliable, however we will consider the following future features:

  • Multi Availability Zones
  • Regional failover
  • Load balancing

Backend Processing

For services like Bitcoin and other cryptocurrencies the key to successful projects is raw processing of hash algorithms and in the case of Bitcoin that is SHA256. While early miners found it sufficient to mine using GPU (Graphics Processing Units) rigs, which excel at such functions, dedicated ASIC (Application-specific integrated circuit) mining machinery has largely replaced them. It is possible however to pool commodity resources for some crypto currencies and that is an option to explore. It is also relevant that some blockchain projects are looking for alternative ways to distribute mining, again, something that we shall look at.

Front End Systems & User Interfaces

Front end user interfaces are central for the acceptance of blockchain based technologies in the mass market. These systems can be browser based web applications or native applications on smartphones and tablets. They usually connect to backend APIs (Application Programming Interfaces) to request information and to request actions. Wallets, currency exchanges and data analytics products fall into this category.

Data Analytics, Warehousing and Reporting

Such applications are transaction-based and tend to generate a large amount of data that is of interest to many stakeholders including business analysts, developers, regulators and end users.

Profitability and Return on Investment

This setup is NOT a guide to profitably mining cryptocurrencies and is for educational purposes only.

DO NOT WASTE MONEY MINING UNLESS YOU UNDERSTAND WHAT YOU ARE DOING. YOU HAVE BEEN WARNED!

Solution

We wish to leave the debate as to the role of GPU miners in certain applications to one side in favour of presenting some working infrastructure code and having a starting point which can be developed and critiqued further.

Devops

The devops solution concerns having our configuration management in code. The advantage of this is:

  • Knowing what the state of our infrastructure is at any point in time
  • Being able to reproduce the infrastructure in case of a disaster
  • Having transparent, auditable and controlled iteration of our infrastructure
  • Having a clear path forward for secure, stable and scalable infrastructure

Infrastructure as Code

In this case we will use Terraform to create the necessary Infrastructure on Amazon Web Services (AWS), the code will be versioned on a repository with security variables omitted and stored securely. Terraform will specify the network fabric and configure the following:

  • VPC
  • Internet Gateway
  • Nat Gateway
  • Routing Tables
  • Public & Private Subnets
  • Web Server
  • Database Server
  • Miner Instance

Chef-client will install automatically on the required instance and bootstrap themselves pulling roles from Chef Server. Anything can be added to this bootstrap script such as NTP time server, Git version control as well as User and Group management. for more complex environments Docker and or Mesos, DC/OS or other Distributed Kernels can help elevate your product or platform to state-of-the-art systems.