# About the Middleware Order that Traefik apply

**URL:** <https://community.traefik.io/t/about-the-middleware-order-that-traefik-apply/11534>\
**Category:** Traefik v2\
**Tags:** middleware\
**Created:** [August 20, 2021, 4:54pm UTC](https://community.traefik.io/t/about-the-middleware-order-that-traefik-apply/11534 "2021-08-20T16:54:49Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![mattvasc-opus](https://avatars.discourse-cdn.com/v4/letter/m/e36b37/32.png) [@mattvasc-opus](https://community.traefik.io/u/mattvasc-opus)\
**Post date:** [August 20, 2021, 4:54pm UTC](https://community.traefik.io/t/about-the-middleware-order-that-traefik-apply/11534/1 "2021-08-20T16:54:49Z")

</div>

Hi guys, I did open this Github Issue:

> <https://github.com/traefik/traefik/issues/8384>
>
> \### Welcome!
> 
> \- \[X\] Yes, I've searched similar issues on \[GitHub\](https://github….com/traefik/traefik/issues) and didn't find any.
> \- \[X\] Yes, I've searched similar issues on the \[Traefik community forum\](https://community.containo.us) and didn't find any.
> 
> \### What did you do?
> 
> Hi guys, sup?
> 
> I'm running Traefik with a service that has two instances, and using three middlewares: 
> \- path-strip, 
> \- retry
> \- circuitbreaker 
> 
> My idea is to use the retry middleware before the circuitbreaker to redirect to the other instance, if the one that the Traefik target at the moment (due round robin) is off.
> 
> But I get different results according to the order of the middleware are defined.
> 
> 
> \### What did you see instead?
> 
> Assuming that I kill one instance, leaving only the other one instance running.
> 
> If I define the middleware's list on the following order:
> - response-check
> - test-retry
> - path-strip
> 
> The circuit breaker will never enter on the open state, but if I define in the order:
> - test-retry
> - response-check
> - path-strip
> 
> The circuit breaker will always get triggered.
> 
> Shouldn't the retry middleware take precedence over the circuitbreaker? 
> 
> Or the Traefik evaluates the middlewares in the backwards direction?
> 
> I got the same behavior using the chain middleware.
> (That was asked here https://github.com/traefik/traefik/issues/8218)
> 
> 
> 
> \### What version of Traefik are you using?
> 
> Running traefik on bare metal (Windows 10), version 2.4.13.
> 
> \### What is your environment & configuration?
> 
> the configuration file (traefik.yml):
> \`\`\`yaml
> providers:
> file:
> directory: "C:/service\_routes"
> watch: true
> 
> entryPoints:
> web:
> address: ":8999"
> traefik:
> address: ":9000"
> 
> api:
> insecure: true
> dashboard: true
> debug: true
> \`\`\`
> 
> The only service configuration file (service1.yml)
> \`\`\`yaml
> http:
> routers:
> router0:
> entryPoints:
> - web
> middlewares:
> - response-check
> - test-retry
> - path-strip
> 
> service: service-foo
> rule: Path(\`/foo\`)
> 
> middlewares:
> chain-midleware:
> chain:
> middlewares:
> - response-check
> - test-retry
> - path-strip
> path-strip:
> stripprefix:
> prefixes: /foo
> response-check:
> circuitbreaker:
> expression: ResponseCodeRatio(500, 600, 0, 600) \> 0.1
> test-retry:
> retry:
> attempts: 2
> 
> 
> services:
> service-foo:
> loadBalancer:
> servers:
> - url: http://127.0.0.1:9001
> - url: http://127.0.0.1:9002
> passHostHeader: false
> 
> \`\`\`
> 
> 
> 
> \### If applicable, please paste the log output in DEBUG level
> 
> N.A.

But it was marked as a configuration issue.

I'm not sure if it is the case, since I do know how to do a workaround to get things working, but the "strange" behavior is still there.

Does traefik evaluate the middlewares on the backwards direction?
