Implement a Custom Error Page for a Load Balancer Using Cloud Native Services

Improve your user's experience by replacing default load balancer error messages with custom error messages created using cloud native monitoring, notification, and functions services.

Oracle Cloud Infrastructure Load Balancing service improves resource utilization, facilitates scaling, and ensures high availability. You can configure multiple load balancing policies and application-specific health checks to ensure that the load balancer directs traffic only to healthy instances. If one or more of the back-end servers report as unhealthy, a user trying to access the load balancer listener receives a standard error code and message as a response. However, by using Oracle Cloud Infrastructure Monitoring, Oracle Cloud Infrastructure Notifications, and Oracle Functions services, end-users can be served with a custom error page hosted by Oracle Cloud Infrastructure Object Storage service. This reference architecture showcases such a scenario to provide a better end-user experience.

Architecture

This reference architecture uses native Oracle Cloud Infrastructure Monitoring and Notification services to respond to load balancer threshold conditions and to call Oracle Functions to evaluate the condition and to use redirect rules to forward custom error messages stored in Oracle Cloud Infrastructure Object Storage.

Oracle Cloud Infrastructure Monitoring defines an alarm that triggers every time unhealthy load balancer back-end servers hit a threshold value. The Oracle Cloud Infrastructure Notifications service sends the alarm message to subscribers which, in this case, includes a function. When notified, the function implements the necessary logic to enable or disable rule sets that are attached to a load balancer listener. A URL redirect rule evaluates an incoming URL and redirects it to a custom error page in Oracle Cloud Infrastructure Object Storage which the load balancer listener forwards to end-users.

The following diagram illustrates this reference architecture.



The Oracle Functions architecture has the following components:

  • Region

    An Oracle Cloud Infrastructure region is a localized geographic area that contains one or more data centers, called availability domains. Regions are independent of other regions, and vast distances can separate them (across countries or even continents).

  • Availability domains

    Availability domains are standalone, independent data centers within a region. The physical resources in each availability domain are isolated from the resources in the other availability domains, which provides fault tolerance. Availability domains don’t share infrastructure such as power or cooling, or the internal availability domain network. So, a failure at one availability domain is unlikely to affect the other availability domains in the region.

  • Virtual cloud network (VCN) and subnets

    A VCN is a customizable, software-defined network that you set up in an Oracle Cloud Infrastructure region. Like traditional data center networks, VCNs give you complete control over your network environment. A VCN can have multiple non-overlapping CIDR blocks that you can change after you create the VCN. You can segment a VCN into subnets, which can be scoped to a region or to an availability domain. Each subnet consists of a contiguous range of addresses that don't overlap with the other subnets in the VCN. You can change the size of a subnet after creation. A subnet can be public or private.

  • Load balancer

    The Oracle Cloud Infrastructure Load Balancing service provides automated traffic distribution from a single entry point to multiple servers in the back end.

  • Functions

    Oracle Functions is a fully managed, multitenant, highly scalable, on-demand, Functions-as-a-Service platform. It is powered by the Fn Project open source engine. Functions enable you to deploy your code, and either call it directly or trigger it in response to events. Oracle Functions uses Docker containers hosted in Oracle Cloud Infrastructure Registry.

  • Notifications

    The Oracle Cloud Infrastructure Notifications service broadcasts messages to distributed components through a publish-subscribe pattern, delivering secure, highly reliable, low latency, and durable messages for applications hosted on Oracle Cloud Infrastructure.

  • Monitoring

    Oracle Cloud Infrastructure Monitoring service actively and passively monitors your cloud resources using metrics to monitor resources and alarms to notify you when these metrics meet alarm-specified triggers.

  • Object storage

    Object storage provides quick access to large amounts of structured and unstructured data of any content type, including database backups, analytic data, and rich content such as images and videos. Use standard storage for "hot" storage that you need to access quickly, immediately, and frequently. Use archive storage for "cold" storage that you retain for long periods of time and seldom or rarely access.

Recommendations

Your requirements might differ from the architecture described here. Use the following recommendations as a starting point.

  • VCN

    When you create a VCN, determine the number of CIDR blocks required and the size of each block based on the number of resources that you plan to attach to subnets in the VCN. Use CIDR blocks that are within the standard private IP address space.

    After you create a VCN, you can change, add, and remove its CIDR blocks.

    In this architecture, the function is hosted on a private regional subnet in the VCN. back-end servers are hosted in a private subnet accessed from a load balancer in a public subnet.

  • Functions

    Oracle Functions supports Python, Java, Node, Go, and Ruby. Use a programming language of your choice. Always enable logging to allow debugging if an error occurs. In this architecture, Python programming is used to develop the functions logic that adds or removes rule sets.

  • Object Storage

    This architecture uses standard Oracle Cloud Infrastructure Object Storage to host a custom web page which is served as a response to end-user requests.

  • Monitoring

    Oracle Cloud Infrastructure Monitoring uses metrics to monitor resources and alarms to notify you when these metrics meet alarm-specified triggers. In this architecture, the load balancer publishes metrics and the alarm is triggered when the UnHealthyBackendServers metric is equal to the total number of available back ends for more than three minutes. A separate alarm removes the custom web page response when the UnHealthyBackendServers metric is less than the total number of available back ends for more than three minutes.

  • Notifications

    Oracle Cloud Infrastructure Notifications publishes messages when event rules are triggered, alarms are breached, or someone directly publishes a message. In this case, Oracle Cloud Infrastructure Notifications is used to trigger the functions when the alarm is fired.

Considerations

  • Availability

    Oracle ensures high availability of the functions, monitoring, and notifications services, which are cloud native and fully managed. Oracle Functions automatically and seamlessly scales horizontally to serve all the incoming requests.

  • Manageability

    This architecture uses Python to write the function logic. The infrastructure is provisioned using Terraform.

  • Security

    Use policies to restrict who can access the Oracle Cloud Infrastructure resources that your company has and how they can access them.

    For Object Storage, encryption is enabled by default and can’t be turned off.

    All access to functions deployed in Oracle Functions is controlled through Oracle Cloud Infrastructure Identity and Access Management (IAM). IAM allows both function management and function invocation privileges to be assigned to specific users and user groups.

  • Cost

    You pay for only the resources used while a function is running.

Deploy

The Terraform and function code for this reference architecture is available in GitHub.

The GitHub repository includes the Terraform code to create the infrastructure for this reference architecture. GitHub also includes the function code that provides decision-making logic based on notifications and rule sets.

  1. Go to GitHub.
  2. Clone or download the repository to your local computer.
  3. Follow the instructions in the README document.