Modernize a monolithic application without a rewrite
Put an Application in front of a monolith, move one route at a time to a Function on Azion, and roll a route back by turning its rule off.
A platform or application team runs a monolithic application in its own data center or in a cloud region, and cannot afford to rewrite it in one project. The team puts an Application on Azion in front of the monolith, so every route keeps reaching the monolith until the team moves it. In this design, one read route moves to a Function on Azion that reads its data from SQL Database. Every other route still reaches the monolith through a Connector, and turning the route’s rule off rolls it back. The result is measured by the share of requests served without reaching the monolith, the latency of migrated routes, and zero downtime during each cut-over.
This use case does not cover moving the whole application to a new origin in one step, or the security hardening of the monolith.
Prerequisites
- An Azion account. If you do not have one, create an account.
- An Application that serves the monolith through a Connector, a rule that sends every request to that Connector, and a Workload. To create them, refer to Applications quickstart.
- Functions on that Application, which the Run Function behavior requires. A new Application has Functions on already. To check it, refer to Main Settings.
Required products
| The modernization needs | Which means | Product | Documented in |
|---|---|---|---|
| A migrated route that Azion answers | A Function, instantiated on the Application, that builds the route’s response | Functions | Functions quickstart |
| The state of the migrated route | A table the Function reads through the read replica of a database | SQL Database | Query a database from a function |
| Routes that move one at a time and roll back | A rule per migrated route, with the Run Function behavior and its active field |
Functions | Run a function on one path, and roll it back |
| Sessions and lookups, as a design option | A value the Function reads by a key the request carries | KV Store | KV Store API |
| Cacheable responses from either side | A cache setting applied by a rule with Set Cache Policy | Cache | Cache settings |
| The traffic split per route | The requests of the workloadBreakdownMetrics dataset grouped by path and upstream address |
Real-Time Metrics | Real-Time Metrics GraphQL fields |
Reference architecture
This page builds the Strangler façade for legacy applications. An Application on Azion processes every request for the domain, and each migrated path goes to a Function while every other path goes to the monolith.
Solid arrows carry the request, dotted arrows carry the response, and thick arrows carry the request records and the team’s rule changes, which run apart from any request. Each label starts with the number of the dataflow step it belongs to.
Dataflow
- A client’s request reaches the Workload on the domain, which forwards it to the Application. The Application runs its Request Phase rules in order, reading the path and the method of the request.
- The first rule matches every path and sets the Connector to the monolith, so a route nobody moved keeps reaching the monolith. The monolith’s response returns to the Application, which delivers it to the client.
- A later rule matches
GET /api/storesand runs the Function Instance. The Function’s response is what the Application delivers to the client. - The Function opens
stores-dbby name, reads thestorestable from a read replica, and answers with JSON built from the rows it receives. A migrated route can also read sessions and lookups from KV Store, or call the monolith’s API for a table the monolith still owns. That answer returns to the Function, not to the client. - Real-Time Metrics sums the requests by path and upstream address, by the hour. There,
127.0.0.1:1666marks Azion Runtime, and the monolith’s address marks the routes it still serves. - The team moves the next route with a new rule. To roll a route back, the team turns its rule off, and the next requests to that path match only the first rule and reach the monolith.
Platform Resources
- Applications: one Application processes every request for the domain, which the Workload forwards to it. Every request crosses the Application, so a route can move without a DNS change or a client change.
- Rules Engine: the Feature of the Application that routes per path. A rule for every path sets the Connector, and one later rule per migrated route runs its Function Instance. Matching rules run in order, so the later rule wins for its path.
- Functions: a Function runs each migrated route on Azion Runtime. The Run Function behavior that invokes its Function Instance requires Functions on the Application.
- Connectors: a Connector routes requests to the monolith. Every route that is not migrated, and every route rolled back, ends at it.
- SQL Database: holds the state of migrated routes. A Function opens a database by name, and a migrated route reads it from a read replica. Writes reach the main instance through
Azion.Sqlor the Azion API, or stay on the monolith until their table moves. - KV Store: holds sessions and lookups, a design option for a route that reads a value by a key the request carries.
- Cache: stores cacheable responses from either side. Cache stores a response whether the origin or a Function builds it. A cache setting applied by a rule with Set Cache Policy therefore caches the monolith’s responses and the Function’s responses alike.
- Real-Time Metrics: shows the traffic split per route, grouping requests by path and upstream address, where
127.0.0.1:1666marks Azion Runtime. The status codes of the Application show the error rate during each cut-over.
Other designs for this use case
- Middleware layer over a legacy origin: for teams that need new behavior before they can move any code, such as authentication checks, response personalization, or header and HTML rewrites. A Function runs before the call to the monolith, in the Request Phase, and a Function written in Lua can also run after it, in the Response Phase. They change the request or the response, so no path stops reaching the monolith. The monolith stays in the request flow and the failure flow of every route.
How the design works
This section explains the data of the migrated route, the Function that answers it, and the rule that cuts the route over and rolls it back.
The route’s data
The migrated route reads its data from a table that the team writes through the Azion API. A Function reads SQL Database from a read replica, and the route reads there and never writes. This page moves a read route whose data the team now owns in SQL Database. The stores table holds every store location, and the monolith no longer serves the list.
The migrated route
The migrated route is a Function that answers GET /api/stores with the rows of the stores table. The Function reads the database through the Azion.Sql global, which takes the database name and no token.
The cut-over and the rollback
The cut-over is a rule that runs the stores-route Function Instance for GET /api/stores. It comes after the rule that sends every path to the monolith, and the Function’s response is what the client receives. The rule matches the method as well as the path, so a POST to /api/stores still reaches the monolith.
The two conditions sit in two criteria groups, because groups join with and: a request matches only when its path is /api/stores and its method is GET.
The rollback turns the rule off, "active": false in the API. With Debug Rules on, the rules that ran on a request appear in Real-Time Events and Data Stream, so a cut-over that does not answer shows whether its rule ran.
Measuring results
| Metric | Where to read it | What working looks like |
|---|---|---|
| Share of requests served without reaching the monolith | workloadBreakdownMetrics grouped by requestPath and upstreamAddr, in hour buckets, with the requests sum. Rows with 127.0.0.1:1666 are the requests Azion Runtime answered. Refer to Query the workloadBreakdownMetrics dataset |
Each migrated path moves to 127.0.0.1:1666, and the monolith’s rows shrink route by route |
| Latency of migrated routes | The Request Time of HTTP Requests records in Real-Time Events, filtered to the migrated path. Refer to Data sources | The migrated route answers no slower than the monolith did for the same path |
| Downtime during each cut-over | In Azion Console, the Status Codes dashboard of Real-Time Metrics, filtered to the Workload. Refer to Break down requests by status code | The HTTP Status Codes 5XX chart stays at its level from before the cut-over while the rule spreads |
Best practices
- Move read routes first. A Function reads SQL Database from a read replica, and it can also write through
Azion.Sql. Even so, a route that writes keeps reaching the monolith, or calls the monolith’s API from the Function, until its writes have a new owner. For the connection a function opens, refer to SQL Database API. - Give every migrated route its own rule. A rule per route makes each rollback one switch that touches no other route. Keep the rule that sends every path to the monolith first, so a rule turned off falls back to it.
- Match the method as well as the path. A path often carries both reads and writes. Matching
GETmoves the read and leaves the write on the monolith until it moves on its own. - Bind integers in queries. A JavaScript string passed as a query parameter is refused with
TypeError: unknown variant `String`, so look a record up by a numeric key. For the parameter forms, refer to Parameters. - Keep sessions and lookups in KV Store when a migrated route needs them. A key the request already carries, such as a session ID, reads in one call from the Function. For the client, refer to KV Store API.