Widemesh Component: Services

Widemesh Services

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.

Commands

Each Service can launch the source code in different ways; the following command prepares the worker to run the app with the queue argument:

mesh svc update worker --command "app queue"

While the 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.

Abilities

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.

There are only two types of services: Workers and Web Services.

Workers

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.

Web Service

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 worker --endpoint https://top.widemesh.dev

A Web Service can be reverted to a Worker with mesh service unpublish:

mesh svc unpublish worker --endpoint https://top.widemesh.dev

Intra-DNS Resolution

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:

<stack-name>-<service-name>

Example:

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:

POST http://finance-payments/payments

Widemesh directs the HTTP request to any healthy Instance of the payment service.

Scaling

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 web:

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 list:

mesh service ls