{"id":17036,"date":"2025-04-17T08:48:18","date_gmt":"2025-04-17T15:48:18","guid":{"rendered":"https:\/\/www.couchbase.com\/blog\/?p=17036"},"modified":"2025-06-13T22:04:18","modified_gmt":"2025-06-14T05:04:18","slug":"high-availability-automatic-failover-app-services","status":"publish","type":"post","link":"https:\/\/www.couchbase.com\/blog\/high-availability-automatic-failover-app-services\/","title":{"rendered":"Ensuring High Availability with Automatic Failover for App Services"},"content":{"rendered":"<p><span style=\"font-weight: 400;\">In modern applications, continuous connectivity is key\u2014especially for mobile apps relying on backend services. In this blog, we\u2019ll walk through a Python-based solution that monitors the health of your app service servers and automatically fails over to a secondary server if needed. This sample code uses HTTP health checks and WebSocket connection endpoints to ensure that your application always connects to a healthy service.<\/span><\/p>\n<h2>Overview<\/h2>\n<p><span style=\"font-weight: 400;\">The solution involves two types of endpoints:<\/span><\/p>\n<ol>\n<li style=\"list-style-type: none;\">\n<ol>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Health check URLs<\/b>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"2\"><span style=\"font-weight: 400;\">These endpoints (e.g., <\/span><span style=\"font-weight: 400;\"><code>https:\/\/...\/_ping<\/code><\/span><span style=\"font-weight: 400;\">) are polled using <em>HTTP <\/em><\/span><em><span style=\"font-weight: 400;\">HEAD<\/span><\/em><span style=\"font-weight: 400;\"> requests.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"2\"><span style=\"font-weight: 400;\">They determine if the app service server is healthy.<\/span><\/li>\n<\/ul>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Connection endpoints<\/b>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"2\"><span style=\"font-weight: 400;\">These are the WebSocket URLs (e.g., <\/span><span style=\"font-weight: 400;\"><code>wss:\/\/...\/primary<\/code><\/span><span style=\"font-weight: 400;\">) that your application uses to interact with the backend.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"2\"><span style=\"font-weight: 400;\">The active connection endpoint is updated based on the health check results.<\/span><\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<\/li>\n<\/ol>\n<p><span style=\"font-weight: 400;\">If the primary server\u2019s health check fails consecutively, the failover logic will switch the application\u2019s connection to the secondary server.<\/span><\/p>\n<h2>The code in detail<\/h2>\n<p><span style=\"font-weight: 400;\">Below is the complete code with inline comments and detailed explanations:<\/span><\/p>\n<pre class=\"nums:false lang:python decode:true\">import logging\r\nimport threading\r\nimport requests\r\nfrom time import sleep\r\n\r\n# Configure logging to show time-stamped messages at INFO level.\r\nlogging.basicConfig(level=logging.INFO, format='%(asctime)s %(levelname)s: %(message)s')\r\n\r\n# --------------------------------------\r\n# Health Check URLs (App Service Servers)\r\n# --------------------------------------\r\n# These URLs are used for health checking the servers by sending HEAD requests.\r\nhealth_check_urls = {\r\n\u00a0\u00a0\u00a0\u00a0\"primary\": \"https:\/\/XXXXXXXXXXXXXX.apps.cloud.couchbase.com:4984\/_ping\",\r\n\u00a0\u00a0\u00a0\u00a0\"secondary\": \"https:\/\/XXXXXXXXXXXXXX.apps.cloud.couchbase.com:4984\/_ping\"\r\n}\r\n\r\n# -------------------------------------\r\n# Connection Endpoints (WebSocket URLs)\r\n# -------------------------------------\r\n# These endpoints are what your application actually uses for connections.\r\nconnection_urls = {\r\n\u00a0\u00a0\u00a0\u00a0\"primary\": \"wss:\/\/XXXXXXXXXXXXXX.apps.cloud.couchbase.com:4984\/primary\",\r\n\u00a0\u00a0\u00a0\u00a0\"secondary\": \"wss:\/\/XXXXXXXXXXXXXX.apps.cloud.ucouchbase.com:4984\/secondary\"\r\n}\r\n\r\n# The variable `active_cluster` tracks which server is currently active.\r\nactive_cluster = \"primary\"\r\n\r\n# This variable holds the actual WebSocket URL used by your application.\r\nactive_connection_url = connection_urls[active_cluster]\r\n\r\ndef is_cluster_healthy(url):\r\n\u00a0\u00a0\u00a0\u00a0\"\"\"\r\n\u00a0\u00a0\u00a0\u00a0Perform a health check using a HEAD request against the provided URL.\r\n\u00a0\u00a0\u00a0\u00a0Returns True if the response status is 200; otherwise, returns False.\r\n\u00a0\u00a0\u00a0\u00a0Logs the status code and headers for troubleshooting.\r\n\u00a0\u00a0\u00a0\u00a0\"\"\"\r\n\u00a0\u00a0\u00a0\u00a0try:\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0response = requests.head(url, timeout=5)\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0logging.info(f\"Health Check Response for {url}\")\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0logging.info(f\"\u00a0 Status Code: {response.status_code}\")\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0logging.info(\"\u00a0 Headers:\")\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0for header, value in response.headers.items():\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0logging.info(f\"\u00a0 \u00a0 {header}: {value}\")\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0if response.status_code == 200:\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0logging.info(f\"{url} is healthy!\")\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0return True\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0else:\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0logging.warning(f\"{url} might be unhealthy or unreachable.\")\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0return False\r\n\u00a0\u00a0\u00a0\u00a0except requests.exceptions.RequestException as e:\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0logging.error(f\"Health check failed for {url}: {e}\")\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0return False\r\n\r\ndef health_check_worker():\r\n\u00a0\u00a0\u00a0\u00a0\"\"\"\r\n\u00a0\u00a0\u00a0\u00a0A background worker that checks the health of the active server every 3 seconds.\r\n\u00a0\u00a0\u00a0\u00a0If the active server fails health checks for more than 9 consecutive times,\r\n\u00a0\u00a0\u00a0\u00a0the worker attempts to switch to the other server.\r\n\u00a0\u00a0\u00a0\u00a0\"\"\"\r\n\u00a0\u00a0\u00a0\u00a0global active_cluster\r\n\u00a0\u00a0\u00a0\u00a0global active_connection_url\r\n\r\n\u00a0\u00a0\u00a0\u00a0consecutive_failures = 0\r\n\r\n\u00a0\u00a0\u00a0\u00a0while True:\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0sleep(3)\u00a0 # Wait 3 seconds between checks.\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0# Use the HTTP health check endpoint for the active cluster.\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0current_health_url = health_check_urls[active_cluster]\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0logging.info(f\"Health check: Checking {active_cluster} at {current_health_url}...\")\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0if is_cluster_healthy(current_health_url):\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0consecutive_failures = 0\u00a0 # Reset counter if healthy.\r\n \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0else:\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0consecutive_failures += 1\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0logging.warning(f\"{active_cluster} health check failed {consecutive_failures} time(s).\")\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0# If failures exceed 9 consecutive attempts, try to fail over.\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0if consecutive_failures &gt; 9:\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0logging.error(f\"{active_cluster} is considered down. Attempting to fail over...\")\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0# Determine the new active cluster.\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0new_cluster = \"secondary\" if active_cluster == \"primary\" else \"primary\"\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0new_health_url = health_check_urls[new_cluster]\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0# Check if the new cluster is healthy.\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0if is_cluster_healthy(new_health_url):\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0active_cluster = new_cluster\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0# Update the connection endpoint.\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0active_connection_url = connection_urls[new_cluster]\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0logging.warning(f\"Switched active cluster to {new_cluster}.\")\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0logging.warning(f\"New WebSocket connection endpoint: {active_connection_url}\")\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0else:\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0logging.critical(\"Both clusters appear to be down!\")\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0consecutive_failures = 0\u00a0 # Reset the failure counter after the attempt.\r\n\r\ndef main():\r\n\u00a0\u00a0\u00a0\u00a0\"\"\"\r\n\u00a0\u00a0\u00a0\u00a0Main function to start the health-check worker in a background thread.\r\n\u00a0\u00a0\u00a0\u00a0Keeps the script running indefinitely until interrupted.\r\n\u00a0\u00a0\u00a0\u00a0\"\"\"\r\n\u00a0\u00a0\u00a0\u00a0thread = threading.Thread(target=health_check_worker, daemon=True)\r\n\u00a0\u00a0\u00a0\u00a0thread.start()\r\n\r\n\u00a0\u00a0\u00a0\u00a0logging.info(\"Health check worker started. Press Ctrl+C to exit.\")\r\n\u00a0\u00a0\u00a0\u00a0logging.info(f\"Application will initially connect to: {active_connection_url}\")\r\n\r\n\u00a0\u00a0\u00a0\u00a0try:\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0while True:\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0sleep(1)\u00a0 # Main thread remains alive.\r\n\u00a0\u00a0\u00a0\u00a0except KeyboardInterrupt:\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0logging.info(\"Shutting down health check script.\")\r\n\r\nif __name__ == \"__main__\":\r\n\u00a0\u00a0\u00a0\u00a0main()<\/pre>\n<h2>Key technical points<\/h2>\n<ul>\n<li style=\"list-style-type: none;\">\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Health checks on App Service Servers:<\/b><b><br \/>\n<\/b><span style=\"font-weight: 400;\">The code separates the <\/span><b>health-check endpoints<\/b><span style=\"font-weight: 400;\"> (used for monitoring) from the <\/span><b>connection endpoints<\/b><span style=\"font-weight: 400;\"> (used by your application). This allows you to check server health independently while maintaining a stable connection endpoint.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>HTTP HEAD Requests:<\/b><b><br \/>\n<\/b><span style=\"font-weight: 400;\">Using <\/span><span style=\"font-weight: 400;\">HEAD<\/span><span style=\"font-weight: 400;\"> requests to the<\/span><span style=\"font-weight: 400;\"><code>\/_ping<\/code><\/span><span style=\"font-weight: 400;\">\u00a0endpoint minimizes data transfer while still providing status codes and headers for diagnostics.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Background Thread:<\/b><b><br \/>\n<\/b><span style=\"font-weight: 400;\">The <\/span><span style=\"font-weight: 400;\"><code>health_check_worker<\/code><\/span><span style=\"font-weight: 400;\"> runs in its own daemon thread, allowing continuous health monitoring without blocking the main application thread.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Failover Logic:<\/b>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"2\"><span style=\"font-weight: 400;\">A counter (<\/span><span style=\"font-weight: 400;\"><code>consecutive_failures<\/code><\/span><span style=\"font-weight: 400;\">) tracks consecutive failures.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"2\"><span style=\"font-weight: 400;\">If the count exceeds a set threshold (9 failures), the script attempts a failover by checking the health of the alternate server.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"2\"><span style=\"font-weight: 400;\">Upon a successful health check on the secondary server, the active connection endpoint is updated.<\/span><\/li>\n<\/ul>\n<\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Logging:<\/b><b><br \/>\n<\/b><span style=\"font-weight: 400;\">Detailed logging provides insights into the health check process, including HTTP response status, headers, and failover events. This aids in troubleshooting and monitoring.<\/span><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h2>Adapting for your application<\/h2>\n<ul>\n<li style=\"list-style-type: none;\">\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">You can easily translate and adapt this code to your preferred programming language such as\u00a0 Swift and Kotlin to fit your application\u2019s needs.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">You might integrate this script or logic into your <\/span><b>mobile code<\/b><span style=\"font-weight: 400;\"> (iOS\/Android) or a <\/span><b>backend service<\/b><span style=\"font-weight: 400;\"> that updates the <em>active<\/em>\u00a0endpoint.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">If you are on iOS or Android, consider how often and where you run this code. For example, background tasks or push notifications can trigger health checks in a mobile context.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400;\">If you have a microservice architecture, you might run this failover logic in a small service that exposes a <em>current active URL<\/em>\u00a0to the mobile apps, so they always connect to the correct WSS endpoint.<\/span><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h2>Conclusion<\/h2>\n<p><span style=\"font-weight: 400;\">This sample code provides a straightforward yet powerful mechanism for ensuring high availability in applications by automatically failing over to a backup server when the primary becomes unreachable. By separating the health checks from the connection endpoints, the application ensures that it always connects to a healthy server via WebSocket.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">In a production environment, you may need to adapt and extend the logic to suit your specific requirements, network conditions, and security policies.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Implementing this logic in your mobile application or backend service can greatly improve uptime and resilience, ensuring your users remain connected even during unexpected service interruptions.<\/span><\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In modern applications, continuous connectivity is key\u2014especially for mobile apps relying on backend services. In this blog, we\u2019ll walk through a Python-based solution that monitors the health of your app service servers and automatically fails over to a secondary server [&hellip;]<\/p>\n","protected":false},"author":85152,"featured_media":17039,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"inline_featured_image":false,"footnotes":""},"categories":[10130,1815,2225,9139],"tags":[2126,1782],"ppma_author":[9941,10067],"class_list":["post-17036","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-app-services","category-best-practices-and-tutorials","category-cloud","category-python","tag-high-availability","tag-websocket"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v25.7.1 (Yoast SEO v25.7) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Ensuring High Availability with Automatic Failover for App Services<\/title>\n<meta name=\"description\" content=\"Boost app reliability with Python-based automatic failover. Monitor server health and switch WebSocket connections seamlessly to keep users connected.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.couchbase.com\/blog\/high-availability-automatic-failover-app-services\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Ensuring High Availability with Automatic Failover for App Services\" \/>\n<meta property=\"og:description\" content=\"Boost app reliability with Python-based automatic failover. Monitor server health and switch WebSocket connections seamlessly to keep users connected.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.couchbase.com\/blog\/high-availability-automatic-failover-app-services\/\" \/>\n<meta property=\"og:site_name\" content=\"The Couchbase Blog\" \/>\n<meta property=\"article:published_time\" content=\"2025-04-17T15:48:18+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-06-14T05:04:18+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2025\/04\/blog-high-availability-app-services.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"2400\" \/>\n\t<meta property=\"og:image:height\" content=\"1256\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Nishant Bhatia - Cloud Architect, Rob Hadaway, Sr. Solutions Architect\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Nishant Bhatia - Cloud Architect\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/high-availability-automatic-failover-app-services\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/high-availability-automatic-failover-app-services\/\"},\"author\":{\"name\":\"Nishant Bhatia - Cloud Architect\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/14cc749fce6a626f4e615a0d53efb709\"},\"headline\":\"Ensuring High Availability with Automatic Failover for App Services\",\"datePublished\":\"2025-04-17T15:48:18+00:00\",\"dateModified\":\"2025-06-14T05:04:18+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/high-availability-automatic-failover-app-services\/\"},\"wordCount\":536,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/high-availability-automatic-failover-app-services\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2025\/04\/blog-high-availability-app-services.jpg\",\"keywords\":[\"High Availability\",\"websocket\"],\"articleSection\":[\"App Services\",\"Best Practices and Tutorials\",\"Couchbase Capella\",\"Python\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.couchbase.com\/blog\/high-availability-automatic-failover-app-services\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/high-availability-automatic-failover-app-services\/\",\"url\":\"https:\/\/www.couchbase.com\/blog\/high-availability-automatic-failover-app-services\/\",\"name\":\"Ensuring High Availability with Automatic Failover for App Services\",\"isPartOf\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/high-availability-automatic-failover-app-services\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/high-availability-automatic-failover-app-services\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2025\/04\/blog-high-availability-app-services.jpg\",\"datePublished\":\"2025-04-17T15:48:18+00:00\",\"dateModified\":\"2025-06-14T05:04:18+00:00\",\"description\":\"Boost app reliability with Python-based automatic failover. Monitor server health and switch WebSocket connections seamlessly to keep users connected.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/high-availability-automatic-failover-app-services\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.couchbase.com\/blog\/high-availability-automatic-failover-app-services\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/high-availability-automatic-failover-app-services\/#primaryimage\",\"url\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2025\/04\/blog-high-availability-app-services.jpg\",\"contentUrl\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2025\/04\/blog-high-availability-app-services.jpg\",\"width\":2400,\"height\":1256},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/high-availability-automatic-failover-app-services\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.couchbase.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Ensuring High Availability with Automatic Failover for App Services\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#website\",\"url\":\"https:\/\/www.couchbase.com\/blog\/\",\"name\":\"The Couchbase Blog\",\"description\":\"Couchbase, the NoSQL Database\",\"publisher\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.couchbase.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#organization\",\"name\":\"The Couchbase Blog\",\"url\":\"https:\/\/www.couchbase.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2023\/04\/admin-logo.png\",\"contentUrl\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2023\/04\/admin-logo.png\",\"width\":218,\"height\":34,\"caption\":\"The Couchbase Blog\"},\"image\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/14cc749fce6a626f4e615a0d53efb709\",\"name\":\"Nishant Bhatia - Cloud Architect\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/image\/6b3e33d8e1e728532201181a4b557ec1\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/7d3d3f6f12724ef9095e97d255b64435e9c6b3df4c0e02d34a569a65138719f2?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/7d3d3f6f12724ef9095e97d255b64435e9c6b3df4c0e02d34a569a65138719f2?s=96&d=mm&r=g\",\"caption\":\"Nishant Bhatia - Cloud Architect\"},\"url\":\"https:\/\/www.couchbase.com\/blog\/author\/nishantbhatia\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Ensuring High Availability with Automatic Failover for App Services","description":"Boost app reliability with Python-based automatic failover. Monitor server health and switch WebSocket connections seamlessly to keep users connected.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.couchbase.com\/blog\/high-availability-automatic-failover-app-services\/","og_locale":"en_US","og_type":"article","og_title":"Ensuring High Availability with Automatic Failover for App Services","og_description":"Boost app reliability with Python-based automatic failover. Monitor server health and switch WebSocket connections seamlessly to keep users connected.","og_url":"https:\/\/www.couchbase.com\/blog\/high-availability-automatic-failover-app-services\/","og_site_name":"The Couchbase Blog","article_published_time":"2025-04-17T15:48:18+00:00","article_modified_time":"2025-06-14T05:04:18+00:00","og_image":[{"width":2400,"height":1256,"url":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2025\/04\/blog-high-availability-app-services.jpg","type":"image\/jpeg"}],"author":"Nishant Bhatia - Cloud Architect, Rob Hadaway, Sr. Solutions Architect","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Nishant Bhatia - Cloud Architect","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.couchbase.com\/blog\/high-availability-automatic-failover-app-services\/#article","isPartOf":{"@id":"https:\/\/www.couchbase.com\/blog\/high-availability-automatic-failover-app-services\/"},"author":{"name":"Nishant Bhatia - Cloud Architect","@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/14cc749fce6a626f4e615a0d53efb709"},"headline":"Ensuring High Availability with Automatic Failover for App Services","datePublished":"2025-04-17T15:48:18+00:00","dateModified":"2025-06-14T05:04:18+00:00","mainEntityOfPage":{"@id":"https:\/\/www.couchbase.com\/blog\/high-availability-automatic-failover-app-services\/"},"wordCount":536,"commentCount":0,"publisher":{"@id":"https:\/\/www.couchbase.com\/blog\/#organization"},"image":{"@id":"https:\/\/www.couchbase.com\/blog\/high-availability-automatic-failover-app-services\/#primaryimage"},"thumbnailUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2025\/04\/blog-high-availability-app-services.jpg","keywords":["High Availability","websocket"],"articleSection":["App Services","Best Practices and Tutorials","Couchbase Capella","Python"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.couchbase.com\/blog\/high-availability-automatic-failover-app-services\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.couchbase.com\/blog\/high-availability-automatic-failover-app-services\/","url":"https:\/\/www.couchbase.com\/blog\/high-availability-automatic-failover-app-services\/","name":"Ensuring High Availability with Automatic Failover for App Services","isPartOf":{"@id":"https:\/\/www.couchbase.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.couchbase.com\/blog\/high-availability-automatic-failover-app-services\/#primaryimage"},"image":{"@id":"https:\/\/www.couchbase.com\/blog\/high-availability-automatic-failover-app-services\/#primaryimage"},"thumbnailUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2025\/04\/blog-high-availability-app-services.jpg","datePublished":"2025-04-17T15:48:18+00:00","dateModified":"2025-06-14T05:04:18+00:00","description":"Boost app reliability with Python-based automatic failover. Monitor server health and switch WebSocket connections seamlessly to keep users connected.","breadcrumb":{"@id":"https:\/\/www.couchbase.com\/blog\/high-availability-automatic-failover-app-services\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.couchbase.com\/blog\/high-availability-automatic-failover-app-services\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.couchbase.com\/blog\/high-availability-automatic-failover-app-services\/#primaryimage","url":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2025\/04\/blog-high-availability-app-services.jpg","contentUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2025\/04\/blog-high-availability-app-services.jpg","width":2400,"height":1256},{"@type":"BreadcrumbList","@id":"https:\/\/www.couchbase.com\/blog\/high-availability-automatic-failover-app-services\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.couchbase.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Ensuring High Availability with Automatic Failover for App Services"}]},{"@type":"WebSite","@id":"https:\/\/www.couchbase.com\/blog\/#website","url":"https:\/\/www.couchbase.com\/blog\/","name":"The Couchbase Blog","description":"Couchbase, the NoSQL Database","publisher":{"@id":"https:\/\/www.couchbase.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.couchbase.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.couchbase.com\/blog\/#organization","name":"The Couchbase Blog","url":"https:\/\/www.couchbase.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2023\/04\/admin-logo.png","contentUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2023\/04\/admin-logo.png","width":218,"height":34,"caption":"The Couchbase Blog"},"image":{"@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/14cc749fce6a626f4e615a0d53efb709","name":"Nishant Bhatia - Cloud Architect","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/image\/6b3e33d8e1e728532201181a4b557ec1","url":"https:\/\/secure.gravatar.com\/avatar\/7d3d3f6f12724ef9095e97d255b64435e9c6b3df4c0e02d34a569a65138719f2?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/7d3d3f6f12724ef9095e97d255b64435e9c6b3df4c0e02d34a569a65138719f2?s=96&d=mm&r=g","caption":"Nishant Bhatia - Cloud Architect"},"url":"https:\/\/www.couchbase.com\/blog\/author\/nishantbhatia\/"}]}},"authors":[{"term_id":9941,"user_id":85152,"is_guest":0,"slug":"nishantbhatia","display_name":"Nishant Bhatia - Cloud Architect","avatar_url":"https:\/\/secure.gravatar.com\/avatar\/7d3d3f6f12724ef9095e97d255b64435e9c6b3df4c0e02d34a569a65138719f2?s=96&d=mm&r=g","author_category":"","last_name":"Bhatia - Cloud Architect","first_name":"Nishant","job_title":"","user_url":"","description":""},{"term_id":10067,"user_id":85538,"is_guest":0,"slug":"rob-hadaway","display_name":"Rob Hadaway, Sr. Solutions Architect","avatar_url":{"url":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2024\/12\/Screenshot-2024-12-20-at-10.48.05\u202fAM.png","url2x":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2024\/12\/Screenshot-2024-12-20-at-10.48.05\u202fAM.png"},"author_category":"","last_name":"Hadaway, Sr. Solutions Architect","first_name":"Rob","job_title":"","user_url":"","description":"Rob Hadaway is a Senior Solutions Architect at Couchbase, where he specializes in deploying and optimizing scalable database solutions in cloud and on-premises environments. With a strong technical foundation and a passion for problem-solving, Rob has led complex projects involving AWS EKS, Azure, and Kubernetes, ensuring seamless integration and deployment of Couchbase solutions for clients across various industries.\r\n\r\nRob holds a Master of Science in Information Systems and an MBA from the University of Utah. His technical expertise spans a wide range of tools and technologies, including Python, SQL, Terraform, Docker, Kubernetes, and React.js. He is highly credentialed, holding multiple AWS certifications, as well as Kubernetes Administrator and Developer certifications"}],"_links":{"self":[{"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/posts\/17036","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/users\/85152"}],"replies":[{"embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/comments?post=17036"}],"version-history":[{"count":0,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/posts\/17036\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/media\/17039"}],"wp:attachment":[{"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/media?parent=17036"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/categories?post=17036"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/tags?post=17036"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/ppma_author?post=17036"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}