Skip to content

Instantly share code, notes, and snippets.

@Herman-Adu
Last active February 5, 2026 12:33
Show Gist options
  • Select an option

  • Save Herman-Adu/32ae76ec8234a67d8c53805a31e07e7b to your computer and use it in GitHub Desktop.

Select an option

Save Herman-Adu/32ae76ec8234a67d8c53805a31e07e7b to your computer and use it in GitHub Desktop.
Advanced HAProxy Configuration

Configure your load balancer to distinguish between Write (Primary) and Read (Replica) traffic using Patroni's health endpoints. haproxy

/etc/haproxy/haproxy.cfg

listen postgres_primary bind *:5000 option httpchk GET /primary # 200 OK only from the current leader http-check expect status 200 server pg-node1 10.0.0.1:5432 check port 8008 server pg-node2 10.0.0.2:5432 check port 8008

listen postgres_replicas bind *:5001 option httpchk GET /replica # 200 OK only from healthy standbys http-check expect status 200 server pg-node1 10.0.0.1:5432 check port 8008 server pg-node2 10.0.0.2:5432 check port 8008 Use code with caution.

Step 3: The Playwright + MSW SSR Test Use the next/experimental/testmode/playwright/msw package to define mocks that apply directly to server-side rendering. typescript // tests/ssr-data.spec.ts import { test, expect, http, HttpResponse } from 'next/experimental/testmode/playwright/msw';

test('validates SSR content with mocked API', async ({ page, next }) => { // Intercept the SSR fetch call from the Next.js Server Component next.onFetch((request) => { if (request.url === 'api.strapi.internal') { return HttpResponse.json({ title: 'Resilient Stack 2025' }); } });

await page.goto('/dashboard');

// Assert the server-rendered HTML contains the mocked data await expect(page.locator('h1')).toHaveText('Resilient Stack 2025'); }); Use code with caution.

📈 Strategic Insights for Tech Leads Failover Performance (RTO/RPO) In this architecture, if the primary database node fails: Patroni detects the failure within 2-5 seconds. etcd triggers a leader election. HAProxy detects the change in health-check response and redirects Port 5000 traffic to the new leader. Result: The application experiences a ~10-second blip instead of a total outage. The "Acid Test" Rule Automation is the heart of DevSecOps. By integrating pgbackrest restore --dry-run into a daily GitHub Action, we move from "Passive Backup" to "Active Verification." We don't just store data; we prove we can recover it. 🚀 How to Enable This in Your Environment Update Dependencies: Ensure you are on [email protected] and [email protected]. Deploy Sidecars: Add the pgbackrest container to your docker-compose. Run with Proxy: Execute tests using npx playwright test. Use --ui mode to see real-time network interception for both client and server requests. Professional Wrap-up This stack isn't just about high-availability; it's about confidence. When a Lead Developer can prove that their backups are verified and their SSR components are fully tested against a self-healing database, they transition from "building apps" to "architecting systems." Ready for Article #2? We can dive into "The Ghost in the Machine: Mastering the pgBackRest Sidecar for Point-In-Time Recovery." AI responses may include mistakes. Learn more

undefined undefined 2 sites Experimental test mode for Playwright - GitHub Prerequisites. You have a Next. js project. Update next.config.js. module. exports = { experimental: { testProxy: true, }, } Insta...

GitHub

A New Approach to Mocking Server-Side Requests in E2E Testing 12 Mar 2025 — Handling on the Server On the server side, the following steps are required: Read incoming headers. Get x-mock-request ...

DEV Community

automate if you can To automate your professional growth and technical enablement, I have structured this process into a self-documenting workflow. By treating your "Next.js 15 + Strapi" app as the Primary Source of Truth, you can generate your professional articles directly from your code. 🤖 The "Automation Strategy" (How we deliver) Format: Everything is delivered in Markdown (.md) for native compatibility with VS Code, GitHub, and professional platforms like Dev.to or Hashnode. Next.js 15 Integration: I will provide code "snippets" that you drop into a /content or /docs folder in your app. Your Next.js app will then render these as a "Developer Portfolio" or "Internal Wiki". CI/CD Integration: We will use GitHub Actions to automate the "Acid Test" for your database and simultaneously "push" your Markdown articles to your blog. 📝 Article #2: The Ghost in the Machine Subtitle: Mastering the pgBackRest Sidecar for Point-In-Time Recovery (PITR) Difficulty: Expert / Lead Developer Status: Implementation Ready 📑 Executive Summary High Availability (HA) keeps your site up, but it doesn't protect against data corruption. If a developer accidentally runs a DELETE without a WHERE clause, HA will faithfully replicate that error to all nodes. This article covers the pgBackRest Sidecar—the ultimate safety net that allows you to "rewind" your database to a specific millisecond. 🛠️ The Implementation Guide (VS Code) Step 1: The Sidecar Configuration Add the pgbackrest service to your docker-compose.yml. This container shares the database's data volume but operates independently. yaml

docker-compose.yml

services: pgbackrest: image: registry.opensource.zalan.do/acid/pgbackrest:2.53 # 2025 Latest container_name: pgbackrest_sidecar volumes: - pg_data:/var/lib/postgresql/data:ro # Read-only access to DB data - backup_repo:/var/lib/pgbackrest # Persistent backup storage environment: - PGBACKREST_STANZA=strapi_main - PGBACKREST_REPO1_TYPE=s3 # 2025 Standard: Offsite S3 - PGBACKREST_REPO1_S3_BUCKET=my-safe-backups - PGBACKREST_REPO1_RETENTION_FULL=2 # Keep 2 full cycles Use code with caution.

Step 2: The "Magic" of PITR Unlike a standard backup, pgBackRest captures Write Ahead Logs (WAL) continuously. To restore your database to exactly December 24, 2025, at 14:02:10, you use the following command: bash

Execute within the sidecar container

pgbackrest --stanza=strapi_main --type=time "--target=2025-12-24 14:02:10" restore Use code with caution.

🧠 Technical Analysis: Why This Wins Zero Overhead: The sidecar performs ZSTD compression using its own CPU/RAM, leaving your Primary DB free for Next.js traffic. Delta Restore: pgBackRest only restores the files that have changed, making recovery up to 10x faster than a full restore. Binary Integrity: It validates CRC checksums for every block it copies. If a disk is failing, you’ll know before you need the backup. 🚀 Professional Enablement Checklist Action: Create scripts/check-integrity.sh in your repo to trigger a --dry-run restore. Next.js Integration: Use fs.readFileSync in a Next.js Server Component to display your "Last Successful Backup" date on your admin dashboard. Visibility: Copy this Markdown into your LinkedIn Articles to showcase your understanding of "Business Continuity." What's Next? Next, we will automate the "Acid Test" using GitHub Actions. This is where we prove to the CEO that our backups actually work in an ephemeral environment. Shall I generate the "Novice to Intermediate" version of this for your younger audience, or proceed to the GitHub Actions automation?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment