Writing Microservices

Microservices are a specialization of a service-oriented architecture (SOA), flexible, independently deployable software.

Microservices are an architectural style that structures an application as a collection of loosely coupled services, which implement business capabilities. The microservice architecture enables the continuous delivery and deployment of large, complex applications by naturally dividing it into smaller pieces. This is in contrast to the more traditional approach of a monolithic architecture.

Popularized by companies like Amazon, Netflix, and Twitter, the philosophy has now become mainstream and adopted by countless organizations.

Microservices on ioFog

Microservices on ioFog run inside a Docker container, following the same best practices.

Your microservices can do anything a Docker container can do, from interacting with the physical hardware to hosting a web server. That means most off-the-shelf frameworks and libraries in your favorite language work too!

But because most Edge Compute Networks contain multiple, sometimes even hundreds or thousands, of nodes running in a distributed fashion, ioFog provides an SDK library you can use to ease the burden of communicating between them. The SDK also provides the ability to receive dynamic configuration in your microservice so you don't have to bake them into your containers.

View Available SDKs

Dynamic Configuration

Using the SDK microservices can receive any arbitrary custom configuration JSON remotely, from the Controller. This allows you to change configuration of your microservices at runtime through the Controller, but also prevents you from needing to bake secrets and other keys into your microservice.

Updating a microservice's configuration can then be done from the Controller:

# Get the microservice's ID if you don't already have it

# Use the ID returned from previous command
iofog-controller microservice update \
  --microservice-id <id> \
  --config '
    {
      "myCustomValue": true,
      "someSecretKey": "private-value"
    }
  '

Packaging and Publishing

Microservices on ioFog are packaged as Linux container images, usually using Docker.

The high-level process of creating a new microservice is:

  • Create a project directory
  • Create a Dockerfile with your desired configuration
  • Write the microservice app code itself
  • Build the image with docker build
  • Deploy your image to a Docker registry (e.g. Docker Hub or from the ioFog local cache)
  • Add the registered image to your Controller's catalog
  • Start the microservice from your Controller
{
  "registries": [
    {
      "id": 1,
      "url": "registry.hub.docker.com",
      "isPublic": true,
      "isSecure": true,
      "certificate": "",
      "requiresCert": false,
      "username": "",
      "password": "",
      "userEmail": "",
      "userId": null
    },
    {
      "id": 2,
      "url": "from_cache",
      "isPublic": true,
      "isSecure": true,
      "certificate": "",
      "requiresCert": false,
      "username": "",
      "password": "",
      "userEmail": "",
      "userId": null
    }
  ]
}