Service and Route concept

Can anyone help me to understand the concept of service and route. Let’s say I have two micro service
service user:
GET /users
POST /users
GET /users/1
POST /a-random-uri
… and goes on
service comment:
GET /comments
POST /comments
GET /comments/1
POST /a-random-uri

How should I register those service and paths? I’m using 0.14.0

How you define your Services and Routes is very much up to you, and how granular you wish to apply plugins to each entity.

  1. If both services are available on the same host, and if you were to create a single Service, and a single Route (therefore, a “catch-all” Service/Route), and proxy each request transparently (only the method and path is different for each request), that’d be fine, but you’d be applying plugins to both upstream services unconditionally.
  2. If you were to create a separate Service entity for each of your upstream services, you could:
    a. Point each of them to separate upstream hosts, and separate load-balancing pools, as it most likely already should be the case
    b. Apply different sets of plugins for each Service
  3. Finally, if you were to create not one, but several Routes for each of these Services (e.g. a GET /users and a POST /users Routes), then you’d be able to apply plugins even more granularly (i.e. per endpoint) for each of both Services.

We’d recommend to go at least with 2., which should give you enough flexibility in the future if the need shall arise. But ultimately, the choice is yours and depends on your needs and how you see your services’ architecture evolving in the future.

For a better understanding of Plugins granularity, you should know that Plugins can be applied:

  • Globally (all requests)
  • To a Service
  • To a Route
  • To a Consumer

The following resources might be helpful too: