Selling microservices with 21

Posted by John Granata, Eli Haims, Carl Dong, David A. Harding

Selling microservices with 21 (beta)

21 makes it easy for you to sell bitcoin-payable microservices, allowing you to earn satoshis in the background while your computer runs. This tutorial explains how 21 sell works and helps you set it up locally on your laptop or remotely on a hosted server.

Install 21

Supported platforms

21 sell runs on a number of platforms, but the containerization features it provides vary depending on what platform you use. The table below shows the supported (and planned) platforms organized by how well they isolate the app servers from the important data on your laptop or other devices. A detailed description of each isolation level can be found below the table.

Please note: 21 sell is in beta on all platforms.

21 sell does not provide a VM ("native") 21 sell does provide a VM ("virtualized")
No containers used ("bare") 1 3
  • N/A
Containers used ("containerized") 2
  • AWS EC2 Ubuntu 14.04+
  • Mac OS X 10.7+
  • Ubuntu 14.04+
  • Centos 7

Indicates that 21 sell support is coming soon.*

  1. Native/Bare: on lightweight platforms such as the 21 Bitcoin Computer, where running a VM would add too much overhead and where Docker containerization technology isn't available (because Docker only supports the x86_64 chipset), 21 sell runs microservices as regular system programs.

    This provides the least amount of isolation between the microservice and its host operating system, but dedicated devices such as 21 Bitcoin Computers and DIY 21 Bitcoin Computers are separate hardware from your main working laptop, so you already have good isolation.

  2. Native/Containerized: on platforms that are already virtualized, such as an Amazon AWS Elastic Compute Cloud (EC2) instance, 21 sell does not add any extra virtualization but it does encapsulate each service inside a Docker container.

    This provides reasonably good isolation between the microservices and their host operating system, and since this is a virtual server in a remote data center, it provides excellent isolation from your working laptop and other personal devices.

  3. Virtualized/Bare: we currently have no plans to design for this scenario, but it could be an option for systems that support a VM but which don't support Docker.

  4. Virtualized/Containerized: on platforms that support running Docker inside a VM, such as Mac OS X and Ubuntu installed locally, 21 sell uses both technologies.

    This provides good isolation between the microservices and the host operating system so that the code can be reasonably run on your regular working laptop or other personal devices.

Running the sell service

To get started, you need to install 21:

  1. Use the diagram above to choose your platform. During the beta period, we strongly recommend installing on an AWS EC2 Ubuntu 16.04 instance to provide full isolation between your working laptop and your 21 sell service. Amazon makes this convenient by currently providing 750 free hours of EC2 hosting to new users. However, you may also install on your local laptop if it is one of the supported systems.

  2. Install 21 and follow its instructions to create an account.

  3. At the command line, run 21 login to log into your account.

For more information about installing 21, please see the Introduction to 21.

After you complete the install, you're ready to actually run 21 sell. Open a terminal on your computer, and if you use AWS or any other remote system, ssh into that system. Then run the following command:

21 sell list

This prints a list of the available microservices:

  ping                               ->  Available                            [TRUE]

Tip: run `21 sell start <services>` to start selling a microservice.

You can now start either all of the services or just one service at a time:

  • Start all the available services at once:
21 sell start --all
  • Start just one particular service, such as ping21:
21 sell start ping

Either way, when you run 21 sell, it will check to see if all of its dependencies are satisfied. If any required dependencies do need to be installed, it will prompt you to install them (your output will vary depending on what platform you use and what dependencies you need to install).

On some platforms you will receive a message requesting you log out of your operating system user account. The easiest way to accomplish this is to reboot your device. When you log back in, re-run the sell command:

## Only necessary if you had to log out and log back in
## Start all services, or
21 sell start --all
## Start just one service
21 sell start ping

Let's start all available services. The output will look similar to the following:

Checking dependencies.
  Dependencies                       ->  Installed                            [TRUE]
  21market                           ->  Joined                               [TRUE]
Checking virtual machine status.
  21 virtual machine does not exist. Would you like to create it? [y/N]: y
Configure 21 virtual machine.
Press return to accept defaults.
  Virtual disk size in MB (default = 5000):
  Virtual machine memory in MB (default = 1024):
  Port for micropayments server (default = 8080):
  Network interface (default = zt0):
Creating machine (this may take a few minutes)...
  21 virtual machine                 ->  Created                              [TRUE]
Starting machine (this may take a few minutes)...
  21 virtual machine                 ->  Started                              [TRUE]
Initializing micropayments server.
Please enter your 21 password:

A unique machine wallet has been generated for your micropayments server.
Please write down the following mnemonic and store it in a safe place:

    rate divide matter hidden globe toaster garage version useful garage inmate vast

Press any key to continue ...
Pulling latest images.
Starting services.
  base                               ->  Started                              [TRUE]
  router                             ->  Started                              [TRUE]
  payments                           ->  Started                              [TRUE]
  payments                           ->  Up                                   [TRUE]
  router                             ->  Restarted                            [TRUE]
  ping                               ->  Started                              [TRUE]
  ping                               ->  Up                                   [TRUE]
  router                             ->  Restarted                            [TRUE]

Would you like to publish the sucessfully started services? [y/N]:
  1. Configure VM: The first time you run 21 sell on some platforms, you will be prompted to configure a Virtual Machine (VM), in particular how much of your hard drive and memory (RAM) to dedicate to it. Reasonable defaults are recommended for each parameter.

  2. Join 21market: this requests whether you want to join the 21 network in order to be able to buy and sell endpoints to other 21 users. This is required; the 21 sell service will not start if you do not agree.

  3. Port number: this asks what port you want to use to receive purchases from other 21 users. The default is 8080, but if you already have that port assigned to another service on your device, you can specify a different port number here.

  4. password: enter your account password here to allow 21 sell to receive buffered payments to your account.

  5. Mnemonics: one or more times you will be prompted to record a wallet backup mnemonic (also called wallet words). Please record these words in a safe place; they ensure that you will be able to access most income you receive even if your computer loses data. (Note: income received in open payment channels cannot be recovered using just these wallet words.)

After you've completed all of the prompts, 21 sell will complete its start up.

Sell status

After your services are running, you will probably want to check up on their status from time to time. To do that, run the status command:

21 sell status --detail

The output from the command will look similar to the following if you run it after starting 21 sell:

  ZeroTier One                       ->  Running                              [TRUE]
  21 Marketplace                     ->  Connected                            [TRUE]
                                         Your IP:
  Router                             ->  Running                              [TRUE]
  Payments                           ->  Running                              [TRUE]
  Ping                               ->  Running                              [TRUE]
  Server                             ->  - Buffer       85250 ($0.5746)     
                                         - Onchain          0 ($0.0000)     
                                         - Channels         0 ($0.0000)     
  Ping                               ->  Requests: 9                        
                                         - Buffer       27000 ($0.1820)     
                                         - Onchain          0 ($0.0000)     
                                         - Channels         0 ($0.0000)     
  Ping                               ->  21 buy '[fcce:a977:ee28:e62d:f6d6:0000:0000:0001]:8080/ping/?'

Tip: run `21 sell list` to see available microservices you can sell.

In the Networking section, we see some basic information about your connection to the 21 network.

  • ZeroTier One: this is the Virtual Private Network (VPN) software used by 21 for communication with other buyers and sellers.

  • 21 Marketplace: this is the default network used to connect buyers and sellers. Your IP address on this network is shown below this line.

In the Services section, we see information about the services that you're running. When containerization is available, each of these services is in its own container:

  • Router: this service manages your connection to the 21 network. When you're using virtualization for maximum isolation from your core system, the router is the only service that maintains a connection to your core operating system.

  • Payments: this service handles the payment channels and other payments for all of the apps that you're running, allowing customers to buy from any of your endpoints without having to establish a different payment channel for each app.

  • Ping: this is the ping21 microservice that ships with 21 sell by default. If you have other services enabled, they will also be listed here.

The following diagram shows the relationship between the services, microservices, containers, and virtualization:

Container relationships

In the Balances section is a listing showing how much money your payment server controls. This is similar to the listing you see for your regular wallet when you run 21 sell but the amounts are also converted to USD for your convenience.

In the Transaction Totals section is a listing of each of your services with two data points:

  • Requests: the number of successful purchases of this microservice made in this 21 sell session.

  • Earnings: the amount earned by this microservice during this 21 sell session. The actual amount earned is in satoshis; the conversion to USD here is for your convenience.

In the final Example Usage section, you will see the quick buy command that can be used to purchase each microservice. Any user of 21 can use this command to buy your service after they run 21 market join to join the 21 network.

Stopping the 21 service

Stopping your services in 21 sell is as easy as it was to start them:

  • To stop all services at the same time, run:
21 sell stop --all
  • To stop just one service, such as ping21, run:
21 sell stop ping

For example, if we stop all services, 21 sell will display output similar to the following output:

Stopping services.
  ping                               ->  Stopped and removed                  [TRUE]
  ping                               ->  [Totals]                             [TRUE]
                                         Requests: 10                       
                                         Earnings: $0.2022

Next steps

21 sell is designed to run continuously in the background while your computer does other work, providing you with a constant stream of satoshis you can use to buy APIs from other users of the 21 Marketplace or which you can use to help pay for server hosting.

The better your server uptime---the longer you can keep it running---the greater your chance of having users buy from your microservices.

If you do shutdown your computer or your server, you will need to run 21 sell start --all (or the individual start commands for the particular services you want to run) in order to start them again. For laptops that enter sleep or hibernation modes, 21 sell should automatically resume operation as soon as their network connections start back up.