Decentralization
Decentralization is the first step toward horizontal scaling. It also can be a vital part for a single-server infrastructure.
Good to know
All the docker-compose.yml and .env files are available in the repo.
What is decentralization?
Decentralization is the opposite of centralization.
Meaning, instead of centering and gathering all the services into a single place, you are placing one or more service in one location, while placing other services in other location(s).
This process called decentralization.
In order for us to be able to apply the decentralization principles in appconda, you need first to group appconda infrastructure components into 3 groups.
- Storage - Docker volumes. These are the virtual drives being used by appconda containers. One volume can be in use by more than one container.
- Application - Databases. These components need to have single endpoint - usually - which makes them very hard to scale.
- Services - Endpoints & Workers. These components are logical components. Meaning they don't have any changeable data inside them, which makes them very easy to scale and replicate.
In the process, you will separate those servers in the at-least two servers, placing the storage and applications into one non-replicable server. And, the services into one replicable server.
In this chart, you can see a possible deploying of a decentralized appconda infrastructure when all the replicable services use one, and only one source of truth.
The dashed line represents connection to a storage volumes while the solid one represents connection to an application
Storage
You're going to use the SSHFS - File system over SSH - protocol. This will allow you to share folders from one server to all other servers in the local network.
Ubuntu Style
Is worth noting that in this chapter and the following ones You're going to install all the needed software using Ubuntu 22.04 server.
Usually it means you can run it in any Debian based Linux distros.
When dealing with sshfs you have at least two servers.
- Main — A server that hosts the folders you want to be available over the network.
- Client - one or more servers in the local network that have the Main server folder mounted as a local directory.
Configure the Main server
In the Main server, you've only 2 steps to take:
- Create the folders.
- Create and save a public SSH key.
Create a directory in the home folder and name it share. Then cd into it and create a folder for each of appconda volumes
mkdir /home/share
cd /home/share
mkdir mariadb redis cache uploads certificates functions builds config executor
Creating SSH Keys
You'll now create the SSH key. The private key will be used by the Client servers, while the public one will be added to the Main authorized_keys file.
This process will let the Client servers to connect to the Main server without having to enter a password.
First, generate the SSH key, give it any name you want - sshfs - in this case and an empty passphrase.
> ssh-keygen -t ed25519
Enter file in which to save the key (/root/.ssh/id_ed25519): sshfs
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Now append the sshfs.pub content to the authorized_keys by running:
cat sshfs.pub >> /root/.ssh/authorized_keys
Mounting the sshfs folders
Copy the sshfs (the private key) to the client server /root/.ssh folder and name it id_rsa. Then, set the file permission to 0600 by running:
chmod 600 /root/.ssh/id_rsa
Then, install the sshfs library, and, create the share directory.
apt update
apt install sshfs
mkdir /home/share