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.
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 using potctl
:
# Get the microservice's YAML description file if you don't have it yet:
# $ potctl describe microservice MICROSERVICE_NAME -o my-microservice.yaml
# Edit the YAML file
apiVersion: datasance.com/v3
kind: Microservice
metadata:
name: my-microservice
spec:
agent: ...
application: my-application
config:
myCustomValue: true
someSecretKey: private-value
ports: []
Then you can redeploy your microservice to update its yaml configuration file:
$ potctl deploy -f my-microservice.yaml
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)
- (Optional) Add the registered image to your Controller's catalog
- Deploy the microservice using potctl
It is detailed in our tutorial