Applications
Route requests to your origins, cache responses, and run code with the rules of an Application, then turn on Application Accelerator or Image Processor.
Applications is a Platform Resource that processes the requests received by your Workloads. An Application can run serverless functions, act as a reverse proxy for your origins, or combine the two, on Azion’s distributed infrastructure, from the data center nearest to your user. A serverless function is a Function, code run on demand at each request, with no server for you to provision. A reverse proxy is a server in front of your origin, the server that holds your content. The proxy can answer each request with a cached copy of an earlier origin response, add or remove headers, or route the request to your origin. Every request passes through the proxy, so your clients reach a single domain, and the proxy applies the logic that each origin would otherwise repeat.
An Application receives the requests of a Workload once that Workload’s deployment sets that Application. On each request, the Application runs its rules. A rule can set the Connector that routes the request to your origin, decide whether the response is cached, or run a Function. Use Applications to route each path to its origin, cache responses, add or remove headers, rewrite requests, run your own code on the requests a rule matches, or resize and convert images on demand.
Quickstart Applications referenceRequest path
Creating an Application routes no request to it: a Workload’s deployment has to set that Application first. An Application also reaches an origin only through a rule that sets a Connector. The diagram follows a request that takes that path. In place of an origin, a Function can answer a request: a rule runs the Function with Run Function, and the Function builds the response with no Connector.
Solid arrows carry the request, and dotted arrows carry the response. Each label starts with the number of its step below.
- The request reaches a Workload through one of its domains, and the Workload’s deployment sets the Application. In Azion Console, you set it in the Application field of Deployment Settings. A Firewall that the deployment also sets runs its rules first, and it can stop the request there.
- The Application’s Request Phase rules run in order. When a behavior, the action a rule runs, ends the processing, as Deny (403 Forbidden) does, the Application answers the client, and no later rule runs.
- If a rule with the Set Cache Policy behavior applied a cache setting, Cache looks for a valid copy of the origin response. When Cache holds one, that copy becomes the response, and the origin receives no request.
- Otherwise, the Connector set by a rule with Set Connector routes the request to the origin. If several matching rules carry Set Connector, only the last of them runs.
- The Application’s Response Phase rules then run on the response, and the response reaches the client.
A new Application starts with Cache and Functions on, Application Accelerator and Image Processor off, and no rules.
A change does not take effect at once: it propagates, and Azion guarantees no propagation time. Until the deployment of a new Workload propagates, which can take several minutes, the Workload answers with Azion’s placeholder 404. During that time, answers alternate between the placeholder and the Application’s response, so repeat the request until they agree. For how the two phases work, the order of rules and behaviors, and propagation, refer to How Applications works.
Rule structure
A rule is the unit of logic in an Application. Its criteria test each request, and its behaviors run on a request that matches. To route every request to the Connector that reaches your origin, send this rule as the body of POST /v4/workspace/applications/<application-id>/request_rules:
criteriaholds groups of conditions, and each group starts with a condition whoseconditionalisif. Here,${uri}is the URI without its query string. Every path starts with/, sostarts_withand/match every request. If the rule tests${request_uri}instead, which keeps the query string, the API refuses it with400and error25047while Application Accelerator is off.behaviorslists the actions the rule runs on a matching request.set_connectorroutes the request to the Connector whose ID is inattributes.value. That Connector holds the address of your origin.nameandactivebelong to the rule itself.- You can also build the same rule in Azion Console, as Applications quickstart shows.
When you send the rule, the API answers 202 and returns it with order set to 0. That value is the rule’s position among the Request Phase rules of the Application.
The model matches path-based routing in a reverse proxy: each criterion is a match condition, each behavior is an action, and a Connector holds the address of the backend server.
Resources
Cache, Application Accelerator, and Image Processor act on the requests of an Application. Each Application turns Application Accelerator and Image Processor on separately, and Main Settings shows where in Azion Console and the API.
Cache
Cache is a Platform Resource that stores copies of the responses to the requests received by an Application. Each copy stays in the data center that stored it, and later requests for the same object get that copy until its time to live (TTL) ends. Cache is always on in an Application. It starts storing copies once a Set Cache Policy rule applies a cache setting, which holds the TTLs. Use Cache to:
- Keep static files in the data center nearest to your user
- Serve large video files in fragments, with Large File Optimization turned on in the cache setting
- Answer requests with an expired copy when the origin fails to answer, with stale cache turned on in the cache setting
- Remove a copy when the origin changes, with Real-Time Purge
The Cache overview explains what a cache setting holds, how a request reaches a stored copy, and where to start.
Application Accelerator
Application Accelerator is a Platform Resource that unlocks four capabilities for the cache and the rules of an Application: cache variation, the caching of POST and OPTIONS responses, a Max Age below 60 seconds, and further Rules Engine behaviors and variables. With cache variation, a cache setting tells apart two requests for the same URL by a query-string argument, a cookie, the device group, or the request method, and Cache keeps a separate copy for each value. Application Accelerator starts off in a new Application. Turn it on when one URL has more than one correct response, for example:
- A personalized page
- An API response that changes with its query string
- A catalog that differs by device
- A response to a
POST
The Application Accelerator overview explains what a variation adds to the cache key, what turning it on unlocks, and where to start.
Image Processor
Image Processor is a Platform Resource that builds a new image, the derived image, from an image on your origin. The ims query string of the request describes the derived image, such as ?ims=fit-in/400x400, and even with no ims query string, Image Processor can convert an image to a format the browser accepts. It returns the derived image without saving it as an asset of the account. It starts off in a new Application, and even when it is on, Image Processor processes only the requests that a Request Phase rule with Optimize Images matches. Turn it on when your pages need one image in several sizes, crops, qualities, or formats, such as WEBP for browsers that accept it. Every variant then comes from one file on your origin, so you store and upload only that file.
The Image Processor overview explains how a request becomes a derived image, what ims accepts, and where to start.
Scope and limits
- Phases: every rule belongs to one of two phases. The Request Phase acts on the request before a response exists, and the Response Phase acts on the response that the user receives. You choose the phase when you create the rule, and you cannot change it later. Only Request Phase rules can choose the origin and the cache setting. Rules Engine for Applications lists the variables and behaviors of each phase and the Platform Resource that each one needs.
- Origins: an Application reaches each origin through a Connector, so two rules with two Connectors can route
/api/to one server and every other path to another. The origin behind a Connector can be a web server in your infrastructure, a cloud service, or an Object Storage bucket. Use a bucket as an application origin shows the bucket case. With Load Balancer enabled, one Connector of thehttptype can spread traffic across several origins. Connectors replace the origins that earlier versions of Applications configured on the Application. - Functions: a Function Instance binds one of your Functions to the Application, with its own arguments. A Function Instance belongs to one Application, and it runs only when a rule with Run Function invokes that Function Instance. Functions starts on in a new Application, in its
modules.functions.enabledfield in the API. Only Functions written in Lua run in the Response Phase, as the Function Instance form in Azion Console states:Only Lua functions can be used in the Response phase.For the steps to add your first Function, refer to Instantiate a function on an application. - Cache and images in code: code that reads or writes cached entries runs in a Function and uses the Cache API, because Cache itself cannot run code. A Function that processes images on its own uses the WASM Image Processor library, which is separate from the Image Processor Platform Resource. Where Image Processor stops explains the difference.
- Devices: a device group is a name and a regular expression that the Application compares with the
User-Agentheader of each request. Both uses of a group need Application Accelerator on: a rule tests the group through${device_group}, and a cache setting can keep one copy per group. Applications best practices shows how to write an expression that matches only the devices you mean. - WebSocket: WebSocket Proxy is a Feature of Applications that carries a WebSocket connection between your users and the origin. The connection opens with the
Upgrade: websocketandConnection: upgradeheaders. Azion turns the Feature on for an account only on request, and Support guidelines explains how to ask. Because Azion recycles keepalive connections about every 15 minutes, the client must reopen a WebSocket connection when it closes. - Workloads: a Workload holds the domains, protocols, and certificates that serve the Application, so you configure delivery on the Workload, not on the Application. Test an application through the hosts file shows how to request an Application on your own domain from one device before you change its DNS records. Redirect HTTP to HTTPS works only when the Workload has HTTPS. When the Connector receives a 4xx or 5xx response from your origin, Custom Pages on the Workload sets the error page that the client sees.
- Interfaces: in Azion Console, you create and manage your Applications on the Applications page, where each Application has five tabs: Main Settings, Device Groups, Cache Settings, Functions Instances, and Rules Engine. In the Console, the Clone row action of the Applications list creates a separate Application with the settings of the original, as Clone an application shows. The Azion API serves your Applications at
/v4/workspace/applications, and Azion CLI manages them with commands such asazion create application,azion update application, andazion create rules-engine. You can also create and configure your Applications withazion.config.js, Azion Lib, or the Azion Terraform Provider. If your account has not migrated to API v4, use Applications | v3. - Observability: with Debug Rules on, Real-Time Events and Data Stream show the rules that each request ran, in the
$tracebackfield. Debug Rules starts off in a new Application. It is thedebugfield of the Application in the API, and Main Settings shows where to turn it on in Azion Console. To check one response, send the request withPragma: azion-debug-cache: the response reports its cache status, such asHITorMISS, in thex-cacheheader. Across all requests, Real-Time Metrics shows the traffic of Cache and Tiered Cache. Troubleshoot Applications lists the tools and queries. For traffic that differs from what you see, refer to A problem shows in traffic but not in the responses you request. - Limits: an Application accepts at most 200 rules, counting both phases. Each rule has 1 to 5 groups of 1 to 10 criteria, plus 1 to 10 behaviors. Without Application Accelerator, a cache setting needs a Max Age, its
modules.cache.max_agefield, of at least 60 seconds. One cached object can be as large as 10 GB. Applications limits lists every bound, what happens past it, and the bounds of each Platform Resource nested in Applications. - Billing: a Platform Resource that you turn on can add costs that depend on usage. Azion pricing lists the plans and the usage that each plan includes, and Pricing lists the rates and the metric that each Platform Resource is billed on.
- Terms: the Applications glossary defines the words that the Applications pages use with a specific meaning, such as rule, phase, behavior, cache setting, cache key, and derived image.