-
Notifications
You must be signed in to change notification settings - Fork 0
Setting Up HAProxy for Oracle REST Data Services (ORDS) with the Oracle Database API for MongoDB
This document provides an example of configuring HAProxy as a load balancer in front of Oracle REST Data Services (ORDS) to support the Oracle Database API for MongoDB.
This configuration is designed to:
- Load-balance mongosh, MongoDB Compass, and other MongoDB drivers
- Load-balance ORDS HTTP (8080) and HTTPS (8443) endpoints
- Provide sticky sessions for MongoDB clients
- Automatically fail over to a healthy backend if one ORDS server becomes unavailable
- Provide a real-time monitoring dashboard via the HAProxy stats interface
The result is a resilient, production-ready high-availability configuration for API-driven MongoDB workloads backed by the Oracle Database API for MongoDB.
Before you begin, ensure that:
- Each ORDS server is fully running and configured with the Oracle Database API for MongoDB
- All ORDS servers are reachable on ports 27017, 8080, and 8443
- You have at least one CentOS/Oracle Linux VM for HAProxy
- SELinux is configured appropriately for HAProxy (or disabled)
sudo yum install -y haproxy
sudo systemctl enable haproxyValidate installation:
haproxy -vCopy the configuration below into:
/etc/haproxy/haproxy.cfg
global
log /dev/log local0
maxconn 5000
daemon
# Runtime administrative socket (for monitoring)
stats socket /var/run/haproxy.sock mode 660 level admin
stats timeout 30s
defaults
log global
mode tcp
option tcplog
timeout connect 5s
timeout client 1h
timeout server 1h
###############################################
# FRONTENDS
###############################################
# MongoDB (mongosh / Compass / Node.js)
frontend fe_mongo_27017
bind *:27017
mode tcp
default_backend be_mongo_27017
# HTTP (port 8080)
frontend fe_http_8080
bind *:8080
mode tcp
default_backend be_http_8080
# HTTPS TLS passthrough (port 8443)
frontend fe_https_8443
bind *:8443
mode tcp
default_backend be_https_8443
###############################################
# BACKENDS
###############################################
# MongoDB backend (with failover + stickiness)
backend be_mongo_27017
mode tcp
balance roundrobin
stick-table type ip size 200k expire 30m
stick on src
default-server fall 3 rise 2 on-marked-down shutdown-sessions
server s1 10.0.0.149:27017 check inter 1s
server s2 10.0.0.140:27017 check inter 1s
server s3 10.0.0.214:27017 check inter 1s
# HTTP backend (port 8080)
backend be_http_8080
mode tcp
balance roundrobin
server s1 10.0.0.149:8080 check inter 2s fall 3 rise 2
server s2 10.0.0.140:8080 check inter 2s fall 3 rise 2
server s3 10.0.0.214:8080 check inter 2s fall 3 rise 2
# HTTPS backend (port 8443)
backend be_https_8443
mode tcp
balance roundrobin
server s1 10.0.0.149:8443 check inter 2s fall 3 rise 2
server s2 10.0.0.140:8443 check inter 2s fall 3 rise 2
server s3 10.0.0.214:8443 check inter 2s fall 3 rise 2
###############################################
# HAProxy STATS + MONITORING DASHBOARD
###############################################
listen stats
bind *:8404
mode http
stats enable
stats uri /
stats refresh 5s
stats show-legends
stats auth admin:password123Restart HAProxy with the new configuration:
sudo systemctl restart haproxyFrontends define how HAProxy listens for incoming connections and which backend they should be routed to.
Defines a frontend responsible for handling all inbound MongoDB wire-protocol connections such as:
- mongosh
- MongoDB Compass
- MongoDB drivers (Node.js, Java, Python, Go, etc.)
Listens on all network interfaces on port 27017, the default MongoDB port.
Uses raw TCP proxying required for MongoDB’s binary wire protocol.
Routes all MongoDB client traffic to the backend named be_mongo_27017.
Defines the listener for ORDS HTTP traffic.
Listens on port 8080, typically ORDS's unsecured HTTP endpoint.
Traffic is forwarded as raw TCP; HAProxy does not inspect or terminate HTTP.
Routes HTTP traffic to the backend group for port 8080.
Handles incoming HTTPS requests for ORDS.
Listens on all interfaces on port 8443, used for ORDS HTTPS.
Enables TLS passthrough, meaning HAProxy does not decrypt SSL.
Forwards encrypted HTTPS connections to backend servers running ORDS on port 8443.
Backends define how HAProxy distributes traffic among ORDS nodes, including load balancing, failover, and stickiness behavior.
Defines the backend group that MongoDB clients will be routed to.
Enables raw TCP proxying for MongoDB wire protocol.
Distributes new client connections evenly across ORDS servers.
Creates a table that tracks clients by IP to support session stickiness:
-
type iptracks by source IP -
size 200ksupports large workloads -
expire 30mremoves inactive entries after 30 minutes
Pins each client’s source IP to a specific backend server to maintain stable MongoDB sessions.
Controls health and failover behavior:
-
fall 3: mark server DOWN after 3 failed checks -
rise 2: mark server UP after 2 successful checks -
on-marked-down shutdown-sessions: terminate active sessions when a node fails so clients reconnect immediately
server s1 10.0.0.149:27017 check inter 1s
server s2 10.0.0.140:27017 check inter 1s
server s3 10.0.0.214:27017 check inter 1s
Each line defines:
- server name (
s1,s2,s3) - server IP and port
-
checkenables health checks -
inter 1schecks server health every second
Defines the group of ORDS HTTP servers.
No HTTP inspection—HAProxy forwards traffic directly.
Evenly distributes HTTP connections across ORDS servers.
server s1 10.0.0.149:8080 check inter 2s fall 3 rise 2
server s2 10.0.0.140:8080 check inter 2s fall 3 rise 2
server s3 10.0.0.214:8080 check inter 2s fall 3 rise 2
Meaning:
- check server health every 2 seconds
- mark down after 3 failures
- mark up after 2 successes
Handles encrypted HTTPS traffic for ORDS.
Requires TCP passthrough to maintain end-to-end TLS.
Distributes TLS connections evenly across ORDS servers.
server s1 10.0.0.149:8443 check inter 2s fall 3 rise 2
server s2 10.0.0.140:8443 check inter 2s fall 3 rise 2
server s3 10.0.0.214:8443 check inter 2s fall 3 rise 2
Same health and failover behavior as the HTTP backend.
mongosh "mongodb://matt:xxxx@<HAProxyHost>:27017/matt?authMechanism=PLAIN&authSource=%24external&retryWrites=false&loadBalanced=true&tls=true&tlsAllowInvalidCertificates=true"This configuration provides:
- HAProxy load balancing
- Sticky sessions
- Automatic failover
- TLS passthrough
- ORDS HTTP/HTTPS balancing
- Full stats dashboard
Production-ready and compatible with:
- ORDS
- Oracle Database API for MongoDB
- mongosh
- MongoDB Compass
- MongoDB drivers
flowchart LR
subgraph Clients [Clients]
A1[mongosh]
A2[MongoDB Compass]
A3[Node.js Apps]
A4[REST API Clients - curl, Postman, etc...]
end
subgraph LB [HAProxy Load Balancer - Ports 27017 8080 8443]
LB1[HAProxy, Sticky Sessions, Automatic Failover, Health Checks, Stats Dashboard, TLS Passthrough]
end
subgraph Backend [ORDS and Oracle Database API for MongoDB Servers]
B1[10.0.0.149 ORDS MongoDB API]
B2[10.0.0.140 ORDS MongoDB API]
B3[10.0.0.214 ORDS MongoDB API]
end
subgraph RAC [Oracle Database 3 Node RAC Cluster]
R1[RAC Node 1]
R2[RAC Node 2]
R3[RAC Node 3]
end
%% Client to HAProxy connections
A1 -->|mongodb 27017| LB1
A2 -->|mongodb 27017| LB1
A3 -->|http or https| LB1
%% HAProxy to ORDS cluster
LB1 -->|27017 MongoDB| B1
LB1 -->|27017 MongoDB| B2
LB1 -->|27017 MongoDB| B3
LB1 -->|8080 HTTP| B1
LB1 -->|8080 HTTP| B2
LB1 -->|8080 HTTP| B3
LB1 -->|8443 HTTPS| B1
LB1 -->|8443 HTTPS| B2
LB1 -->|8443 HTTPS| B3
%% ORDS systems to Oracle RAC database
B1 -->|SQL Net| R1
B1 -->|SQL Net| R2
B1 -->|SQL Net| R3
B2 -->|SQL Net| R1
B2 -->|SQL Net| R2
B2 -->|SQL Net| R3
B3 -->|SQL Net| R1
B3 -->|SQL Net| R2
B3 -->|SQL Net| R3
classDef darker fill:#1a1a1a,stroke:#444,color:#fff;
class LB darker;
class Backend darker;
class RAC darker;
- Please feel free to contact Matt DeMarco
- ORDS Documentation Library
https://docs.oracle.com/en/database/oracle/oracle-rest-data-services/ - ORDS Configuration Guide
https://docs.oracle.com/en/database/oracle/oracle-rest-data-services/25.3/ordig/configuring-additional-databases.html - ORDS Architecture Overview
https://docs.oracle.com/en/database/oracle/oracle-rest-data-services/25.3/orddg/developing-REST-applications.html#GUID-EF02529D-79C3-4FB3-89A8-06329878C71B__FIG_FDK_TTL_GTB
- Oracle Database API for MongoDB (Home Page)
https://docs.oracle.com/en/database/oracle/mongodb-api/mgapi/index.html - MongoDB API for Oracle Database – Overview
https://docs.oracle.com/en/database/oracle/mongodb-api/mgapi/overview-oracle-database-api-mongodb.html - MongoDB API for Oracle Database – Supported Driver Features https://docs.oracle.com/en/database/oracle/mongodb-api/mdbag/features-supported.html
- Oracle RAC Overview
https://docs.oracle.com/en/database/oracle/oracle-database/23/racad/index.html - Oracle Net Services Admin Guide
https://docs.oracle.com/en/database/oracle/oracle-database/23/netag/index.html - Configuring Services for RAC
https://docs.oracle.com/en/database/oracle/oracle-database/26/racad/workload-management-with-dynamic-database-services.html
- HAProxy Configuration Manual
https://docs.haproxy.org - HAProxy TLS & SSL Configuration Guide
https://docs.haproxy.org/3.0/configuration/ssl.html - HAProxy Logging & Monitoring
https://docs.haproxy.org/3.0/management.html - Runtime Administration Socket Reference
https://docs.haproxy.org/3.0/management.html#9.3-runtime-api
- Mongosh Documentation
https://www.mongodb.com/docs/mongodb-shell/ - MongoDB Connection String URI Reference
https://www.mongodb.com/docs/manual/reference/connection-string/ - MongoDB TLS/SSL Guide
https://www.mongodb.com/docs/manual/tutorial/configure-ssl/
- SELinux Port Management
https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/7/html/selinux_users_and_administrators_guide/sect-security-enhanced_linux-working_with_selinux-booleans - semanage Port Command Reference
https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/7/html/security_guide/sec-adding_a_port_to_selinux
- Linux Kernel TCP Tuning
https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/8/html/configuring_and_managing_networking/assembly_adjusting-kernel-network-settings_configuring-and-managing-networking - Increasing File Descriptor Limits
https://access.redhat.com/solutions/61334
- MongoDB to Oracle Database API Migration Flow
- Setting Up Oracle REST Data Services (ORDS) with the Oracle Database API for MongoDB
- Enabling TLS with a Self‐Signed Certificate in ORDS for MongoDB API
- ORDS Account Management
- Setting Up HAProxy for Oracle REST Data Services (ORDS) with the Oracle Database API for MongoDB