The following sections describe how the algorithms handle specific rule configurations and request conditions.
With legacy, A before: [B] and B after: [A] record the same dependency, so they always give the same order.
With priority_preserving, the plugin carrying the rule is the one that moves, so the same relationship can produce different orders depending on where you write it.
The following example uses four plugins, listed in priority order: Key Auth (1250), LDAP Auth (1200), Header Cert Auth (1009), and Response Transformer (800).
Here’s how the order changes depending on the algorithm you use:
|
Configuration
|
priority_preserving order
|
legacy order
|
Response Transformer with before: [ldap-auth]
|
- Key Auth
- Response Transformer
- LDAP Auth
- Header Cert Auth
|
- Key Auth
- Response Transformer
- LDAP Auth
- Header Cert Auth
|
LDAP Auth with after: [response-transformer]
|
- Key Auth
- Header Cert Auth
- Response Transformer
- LDAP Auth
|
- Key Auth
- Response Transformer
- LDAP Auth
- Header Cert Auth
|
When several rules interact, priority_preserving places each plugin next to its anchor without searching for the order that disturbs the fewest unconfigured plugins.
The following example uses Key Auth, LDAP Auth, Header Cert Auth, and Response Transformer, listed in priority order.
If you set Header Cert Auth before Response Transformer and Response Transformer before Key Auth, the resulting order looks like this:
- Header Cert Auth
- Response Transformer
- Key Auth
- LDAP Auth
LDAP Auth has no rule but drops from second to last.
The two rules only fix the relative order of Header Cert Auth, Response Transformer, and Key Auth, so LDAP Auth can run in any position and still satisfy them.
For example, running LDAP Auth first is also valid.
priority_preserving places each plugin next to its anchor, so it can move an unconfigured plugin further than necessary.
To keep a plugin in place, add a rule to that plugin.
In this case, setting before: [header-cert-auth] on LDAP Auth makes LDAP Auth run before the other three plugins.
In this case, LDAP Auth with before: [header-cert-auth] makes it run before the other three plugins.
When plugins share a priority, Kong Gateway orders them by plugin name in descending order.
This applies to both algorithms and doesn’t depend on load order.
A cloned plugin without a priority override inherits the priority of its source plugin.
See cloned plugins for details.
Dynamic ordering runs for each request.
A plugin scoped to a Route, Service, or Consumer only takes part in ordering for requests that match its scope.
A scoped plugin that doesn’t match the request can still be the target of another plugin’s before or after rule. It doesn’t run, and its own ordering rules don’t apply.
This means the order can differ between request paths.
If your rules contradict each other, for example Response Transformer with before: [key-auth] and Key Auth with before: [response-transformer], Kong Gateway reports a circular dependency error instead of picking an order.
With legacy, the message is:
There is a circular dependency in the graph. It is not possible to derive a topological sort.
With priority_preserving, the error message also lists the plugins that form the circular dependency.