This tutorial demonstrates how to use gateway partitions in OpenResty Edge.

A gateway partition is a named group of gateway clusters that can run their own configuration, where each cluster is itself a group of gateway servers. So the hierarchy is: a partition contains clusters, and a cluster contains servers. When you assign an application to a partition, only the servers in that partition serve it—servers in other partitions have no configuration for the domain and return “Page Not Found”.

Partitions let you:

  • Isolate internal and external applications so they never share configuration or traffic.
  • Run precise A/B tests by confining a change to a specific set of servers.
  • Roll out updates gradually across your gateway fleet, and roll back to a previous version when needed.

Because configuration changes in OpenResty Edge are pushed to servers without any reload, restart, or binary upgrade, deploying to a partition is fast and safe.

Create a new partition

Let’s go to a web console of OpenResty Edge. This is our sample deployment of the console. Every user would have their own deployment.

Screenshot

First, we will go to the “Gateway Clusters" page. Here you can see a numerous gateway clusters that have been established.

Screenshot

For instance, this gateway cluster is situated in the United States.

Screenshot

There is one gateway server in it.

Screenshot

It is also part of the gateway partition “default”.

Screenshot

Now let’s create a new gateway cluster. Click on “New Gateway Cluster”.

Screenshot

Enter the name of the gateway cluster “edge-test-cluster”.

Screenshot

In OpenResty Edge, a gateway partition consists of multiple gateway clusters as shown in the picture.

Embeded image

So the next step is to add this cluster to a partition.

Click on this drop down box.

Screenshot

We won’t use an existing partition. We’ll create a new one instead.

Click the button “Add Gateway Partition”.

Screenshot

Enter the partition name “edge-test-partition”.

Screenshot

Click the “Create” button.

Screenshot

The newly created partition now appears first in the partition selection dropdown.

Screenshot

Click the “Create” button to create the cluster.

Screenshot

We can see the newly created gateway cluster appears on the cluster list page.

Screenshot

As shown in the picture, a gateway cluster consists of multiple gateway servers.

Embeded image

Now let’s see how to add a gateway server to the newly created gateway cluster.

Here we have already prepared a gateway server.

Screenshot

Click the button “Approve”.

Screenshot

Select the cluster first.

Click on the drop down box and select the cluster we just created.

Screenshot

Enter the public IP address of this server.

Screenshot

Click to approve this server.

Screenshot

The server was added to the gateway cluster successfully.

Screenshot

Create a new application in the new partition

Now let’s create an application in the newly created partition.

Go to the applications page.

Screenshot

Click “New Application”.

Screenshot

Enter the domain name.

Screenshot

Click the partition selection drop down box.

Screenshot

Unselect the partition “default”.

Screenshot

Selecte the partition we just created.

Screenshot

Click the “Create” button.

Screenshot

Create a new page rule

We need to crate a page rule to illustrate how partition works.

Go to the “Page Rules” page.

Screenshot

Click “New Rule”.

Screenshot

Let’s add a new action.

Screenshot

click the action drop down box.

Screenshot

Select the action “output response body”.

Screenshot

Click the “Create” button.

Screenshot

We need to make a new release to push out our new changes.

Screenshot

Click on this button.

Screenshot

Ship it!

Screenshot

Our new release is now synchronized to all our gateway servers.

Screenshot

Now the new page rule has been pushed to all the gateway clusters and servers.

Embeded video

Embeded video

Embeded video

Our configuration changes do NOT require server reload, restart, or binary upgrade. So, it’s very efficient and scalable.

Embeded image

Test the new partition

Let’s go to the gateways clusters page again.

Screenshot

This is the cluster we just created.

Screenshot

Please note that the IP address of the server recently added to this cluster ends with ‘67’.

Screenshot

On the terminal, we use curl to send a request to the gateway server.

curl "http://13.229.144.67" -H "Host: edge-test-partition.com"

Screenshot

You can see that the correct response body has been outputted.

We are now performing the same operation on a server that is not on this partition. Note that this server’s IP ends with .84.

Send the request.

curl "http://3.131.85.84" -H "Host: edge-test-partition.com"

Screenshot

You can see that the gateway server of the other partition returns “Page Not Found”.

Frequently asked questions

What is the difference between a gateway partition and a gateway cluster?

A gateway cluster is a group of gateway servers, and a gateway partition is a group of gateway clusters. Different partitions can use different configurations, which is what lets you isolate applications and target releases to specific servers.

Why does a server in another partition return “Page Not Found”?

An application is bound to the partition you assign it to. Only the gateway servers in that partition have the configuration for the application’s domain, so servers in other partitions respond with “Page Not Found”. The curl tests above show this: the server inside the application’s partition returns the expected response body, while a server outside it returns “Page Not Found”.

When should I use gateway partitions?

Use partitions to separate internal and external applications, to isolate a set of servers for precise A/B testing, and to roll updates out gradually across your gateway fleet with the option to roll back to a previous version.

Do I need to restart the gateway servers to apply partition changes?

No. In OpenResty Edge, configuration changes are synchronized to all gateway servers without any reload, restart, or binary upgrade, so releasing to a partition takes effect quickly and scales to large deployments.

What is OpenResty Edge

OpenResty Edge is our all-in-one gateway software for microservices and distributed traffic architectures. It combines traffic management, private CDN construction, API gateway, security, and more to help you easily build, manage, and protect modern applications. OpenResty Edge delivers industry-leading performance and scalability to meet the demanding needs of high concurrency, high load scenarios. It supports scheduling containerized application traffic such as K8s and manages massive domains, making it easy to meet the needs of large websites and complex applications.

If you like this tutorial, please subscribe to this blog site and/or our YouTube channel. Thank you!

About The Author

Yichun Zhang (Github handle: agentzh), is the original creator of the OpenResty® open-source project and the CEO of OpenResty Inc..

Yichun is one of the earliest advocates and leaders of “open-source technology”. He worked at many internationally renowned tech companies, such as Cloudflare, Yahoo!. He is a pioneer of “edge computing”, “dynamic tracing” and “machine coding”, with over 22 years of programming and 16 years of open source experience. Yichun is well-known in the open-source space as the project leader of OpenResty®, adopted by more than 40 million global website domains.

OpenResty Inc., the enterprise software start-up founded by Yichun in 2017, has customers from some of the biggest companies in the world. Its flagship product, OpenResty XRay, is a non-invasive profiling and troubleshooting tool that significantly enhances and utilizes dynamic tracing technology. And its OpenResty Edge product is a powerful distributed traffic management and private CDN software product.

As an avid open-source contributor, Yichun has contributed more than a million lines of code to numerous open-source projects, including Linux kernel, Nginx, LuaJIT, GDB, SystemTap, LLVM, Perl, etc. He has also authored more than 60 open-source software libraries.