Publishing an API with a 15-minute schema compile
Draft!!
Take an API whose JSON and XSD schemas are so large that DataPower needs 15 minutes or more to compile them. That one fact causes two separate problems, and each needs its own fix.
Two problems, two fixes
The gateway has to compile the schemas before the API can serve a single request. The compiled schema lives in the DataPower cache. That cache is wiped whenever a pod or an appliance restarts.
| Problem | When it happens | Fix |
|---|---|---|
| Outage when publishing a new version | Every schema change | Publish alongside the old version, then products:replace |
| Slow recovery, and a wider blast radius | Pod restart, appliance restart, DR failover | A dedicated gateway service for the large API |
The two fixes do not depend on each other. Use both.
Problem 1: publishing a new version
Publish a changed schema in place and the gateway compiles it while consumers are live. A change of one field costs the same 15 minutes as a rewrite of all of it, and for those 15 minutes the API is the problem.
The fix is to move the wait to a time when nobody is waiting on it.
Step 1: Publish the new version alongside the old one
Do not edit the live Product in place. A new schema is a new version of the API and a new version of the Product. Publish it next to the old one, so the 15-minute compile happens while consumers are still on the old version.
# Create the new API and Product versions
apic create:api --title "Big Schema API" --version 2.0.0 --filename bigapi200.yaml
apic create:product --title "Big Schema" --version 2.0.0 --apis bigapi200.yaml --filename bigproduct200.yaml
# Publish the new version
apic products:publish bigproduct200.yaml
Set the visibility and subscribability of the new Product so that only your test consumer organisation can see and subscribe to it.
Both versions can run side by side on the same base path. The gateway routes by subscription: a consumer subscribed to 1.0.0 reaches 1.0.0, and a consumer subscribed to 2.0.0 reaches 2.0.0. The URL does not change for anyone. Your test consumer exercises 2.0.0 while production stays on 1.0.0.
Step 2: Cut over with replace
Replace is the reason this works. The compile happens when you publish, so by the time you run the replace, the new version is already compiled and tested. No consumer is exposed to the wait.
The command takes the replacement Product as its argument. The mapping file holds the URL of the Product being replaced.
# mapfile.yaml
product_url: https://platform-api.example.com/api/catalogs/{org-id}/{catalog-id}/products/{old-product-id}
plans:
- source: default
target: default
apic products:replace bigproduct:2.0.0 mapfile.yaml \
--scope catalog --catalog prod --org myorg --server mgmt.example.com
This publishes the replacement, moves every subscription to it, and retires the old Product. Every Plan in the old Product must be mapped to a Plan in the new one. The source and target Plan names can be the same or different.
Two rules from the documentation that catch people out:
- The old Product must be Published. The replacement can be Staged, Published, or Deprecated.
- If the replacement is more restrictive on visibility or subscribability than the original, the replace fails.
If you restricted the new Product to a test organisation in Step 1, that is more restrictive than the old Product, so the replace will fail. Widen its visibility to match the old Product first.
If you want a gradual migration
Replace moves everyone at once. If you want to move consumers in groups, there are two alternatives.
| Command | Old Product | Subscriptions |
|---|---|---|
products:replace |
Retired | All migrated at once |
products:migrate-subscriptions |
Left as is | The ones you select |
products:supersede |
Deprecated | Consumers migrate themselves |
migrate-subscriptions does the same job as replace, except that it does not retire the source Product. The destination Product must already be published. In API Manager you pick the Plan, then the subscriptions, then the target Product and Plan. Move a pilot consumer first, watch the analytics, then move the rest, and finish with replace to retire the old version.
supersede deprecates the old Product, blocks new subscriptions, and gives application developers a Migrate this subscription option in the Developer Portal. They choose their own moment.
Problem 2: restarts and DR
Replace does nothing for this one. When a pod or an appliance restarts, the cache is wiped and the schema compiles again from scratch. A DR failover is the same event on a larger scale: the gateway you fail over to has to compile before the API works.
If the large API shares a gateway service with everything else, a restart that should take minutes becomes a 15-minute wait for APIs that have nothing to do with the large schema. Those APIs are in your DR plan too.
Give it its own gateway service
Put the large-schema API on a dedicated gateway service, backed by its own DataPower API Gateway pods.
In Cloud Manager, register a new gateway service in the topology. In API Manager, add it to the catalog where the API is published. Then publish the Product to that gateway service only.
What this buys you:
- A restart of the large-schema pods blocks only that API.
- In a DR failover, every other API comes back at normal speed. Only the large API waits for its compile.
- You can size those pods independently. A compile needs different CPU and memory from normal traffic.
The cost is another set of DataPower pods. It is worth it.
A dedicated gateway service does not make the compile faster. It stops everyone else paying for it. Run at least two pods and restart them one at a time, so a compiled copy is always serving.
Summary
Treat these as two problems. Publish each new schema version alongside the old one and use products:replace to cut over once the compile has finished and the testing is done. Put the large API on its own gateway service so a restart or a DR failover only delays that one API.
Limitations and Notes
- Replace cannot migrate subscribers from a free Plan to a paid Plan automatically.
- If approvals are enabled for the Catalog, the replace goes to Pending until approved.
- Every restart of the dedicated gateway pods pays the full compile cost.
