A service either serves network requests through endpoints for public access over the Internet(Web Service) or serves other services in the environment(Worker) via Middleware or direct HTTP requests.
Each Service in the Stack runs the same version of the code and launches Processes of the built source code in the stack specific command of your choosing.
Each Service can launch the source code in different ways; the following command prepares the
worker to run the app with the
mesh svc update worker --command "app queue"
web service launches the HTTP server:
mesh svc update web --command "app server"
Note: Services may fail to launch the command specified in the Service, to debug any problem with your Service see Monitoring and Debugging.
Here’s a list of abilities of a Service:
- Connect to the Internet
- Connect to Databases and Distributed Queues
- Make outbound requests to the Internet
- Receive inbound requests from other services in the same environment.
- Run programs on periodic schedules
There are three types of services: Workers, Web Services, and Cron Jobs.
A worker is a service that does not service Inbound traffic from the Internet; as soon it’s bound to any Endpoint, it becomes a Web Service.
A cron job is a sub-type of Worker that runs Instances of your programs on a given schedule, for example, assuming you want to run the program with arguments
node send-emails.js on an hourly basis, you can create a cron job as follows:
mesh svc create -n emailsender --schedule "@hourly" -- node send-emails.js
Cron jobs accept most of the cron job syntax; here’s a few examples:
- At 04:05 am:
5 4 * * *
- At 04:06 pm:
5 16 * * *
- On hourly basis:
- Every two minutes:
A web service is any service published through an Endpoint from the Environment, typically the Service in the Stack that contains the user-facing API or Web Application is a web service.
Example, assuming the environment platform alias is
https://top.widemesh.dev you can publish the service
web as follows:
mesh svc publish -n worker --endpoint https://top.widemesh.dev
A Web Service can be reverted to a Worker with
mesh service unpublish:
mesh svc unpublish -n worker --endpoint https://top.widemesh.dev
You can also publish your web services in a sub-path of your domain with
mesh service publish --stack myblog --n web --endpoint www --path /blog
Each Service in the environment contains a Hostname that load balances between the healthy Instances of the Service, which is pretty useful for network-based micro-services, the format of the hostname format is as follows:
You have a service called
web inside the Stack
app, and it wants to make a
POST /payments request to the
payments service of the Stack
finance, it can use the following URL to perform HTTP requests:
Widemesh directs the HTTP request to any healthy Instance of the payment service.
Each Service in the Stack can be scaled independently to a user-defined number of Instances.
Example, the following command instructs Widemesh to launch five instances of the service
mesh svc update web --instances 5
Monitoring and Debugging
Service instances may crash after they start, they may run out of memory and not even start at all because the command contains a typo.
For that you can monitor the status of each Instance, the number of restarts, message, and exit codes of the Instances with
mesh service ls
You can get an interactive shell to a new instance of service with the following command:
mesh service run -n web -- /bin/bash
Note: Some docker base images such as
alpine do not feature
/bin/bash; you can use