MDH GROUP · BLOG

Zero‑Downtime Upgrades for self‑hosted Affilentra: Practical Guide for Safe Schema and Release Migrations

For operators of self‑hosted affiliate platforms like Affilentra, continuous tracking is the lifeblood of the business: every unplanned outage reduces transparency for merchants and partners and endangers commission settlement and trust.

← All posts

Zero‑Downtime Upgrades for self‑hosted Affilentra: Practical Guide for Safe Schema and Release Migrations

Introduction — Why Zero‑Downtime Is Critical for Affilentra

For operators of self‑hosted affiliate platforms like Affilentra, continuous tracking is the lifeblood of the business: every unplanned outage reduces transparency for merchants and partners and endangers commission settlement and trust. Zero‑Downtime upgrades are not a luxury but a prerequisite for operators who want to apply PRO & NETWORK Edition releases with minimal interruption. This guide provides a practical sequence of steps for PHP/MySQL environments to plan and execute schema and release migrations so that tracking availability and data integrity are preserved.

Core Principles Before Implementation

  • Backward compatibility first: Design changes so that old and new codebases can run concurrently.
  • Incremental changes: Break large DDL jumps into small, well‑defined steps.
  • Idempotent migrations: Write scripts so they can run multiple times without side effects.
  • Separation of schema change and business switch: Adjust data structure, validate, then enable application logic.
  • Role awareness: Software operators plan, merchants are informed, partners retain tracking access — communication is mandatory.

Preparation: Checklist Before Every Migration

  • Create a complete backup (schema + data); for large databases: secure a consistent snapshot or mysqldump + binary log position.
  • Implement schema versioning (e.g., a migrations table).
  • Execute a test migration in a staging environment with realistic data loads.
  • Prepare and validate rollback scripts (reverse migrations, restore replication).
  • Configure metrics and alerts: tracking endpoint latencies, error rates, queue lengths, replication lag.
  • Communication tactic: inform merchants/partners if visibility changes may occur.

Migration Patterns for Zero‑Downtime

1) Additive Changes

Adding new fields (nullable, without default) is the safest option. Application code can adopt the new code path gradually while old calls continue unchanged. Example steps:

  • ALTER TABLE t ADD COLUMN new_col VARCHAR(255) NULL;
  • Deploy app version that supports dual‑reads/dual‑writes.
  • Asynchronous backfill, if necessary.
  • Final cleanup: remove old columns only after no application uses them anymore.

2) Shadow Table + Swap

Introduce complex structural changes (e.g., normalization, data type changes) via a new table that you populate in the background and finally exchange atomically using a RENAME swap.

  • CREATE TABLE t_new LIKE t; truncate/modify as needed.
  • A background process copies data incrementally (in chunks) and adheres to transactional batches.
  • During the final cut: enable short dual-write, apply the last deltas, then RENAME TABLE t TO t_old, t_new TO t.
  • Rollback: rename back; t_old remains available.

3) Dual‑Write with Feature Toggle

The application layer writes in parallel to the old and new schema. Read logic can be switched gradually from old to new via a feature toggle. Dual-write requires conflict handling and monitoring, but is highly controllable.

4) Online Index and Long DDL

For large tables avoid blocking DDL. Use proven tools for online schema changes (e.g., gh‑ost, pt‑online‑schema-change) or MySQL mechanisms like ALGORITHM=INPLACE/ONLINE where appropriate. These tools operate in almost all cases without a full table lock and minimize IO spikes, but require testing.

Release Sequence: Order of Steps

  1. Prechecks and open health gate (backups, replication OK).
  2. Schema change: perform additive/online changes, build shadow table if needed.
  3. Monitoring: verify data consistency (row counts, checksums), observe tracking endpoints.
  4. Deploy the new application version in canary steps: allow only one percent of instances/partners to use it.
  5. Feature toggle: roll out the read switch in stages; on issues roll back to the previous toggle level.
  6. Post‑migration: finish backfill, ensure metrics are stable, remove legacy data only after an observation phase.

Backfill Strategies Without Availability Loss

  • Chunked backfill: small batches, pauses between batches, prioritize by recency.
  • Prioritized backfills first for tracking and conversion data that affect billing.
  • Load monitoring: backfill automatically reduces IO during peak times via rate limiting.

Monitoring, Validation and Tests

Monitor during and after the migration:

  • Tracking endpoint error rates and latencies.
  • Disk IO, locks, replication lag.
  • Application logs for schema-related exceptions.
  • Data integrity: sample comparisons, checksums between old and new structures.

Rollback Plan — short, clear, testable

A rollback plan should be defined and tested beforehand. Core elements:

  • Quick restore path: revert RENAME swap, reset feature toggle, or rollback code to the previous version.
  • Binlog-based point-in-time restore for critical data fixes.
  • Rollback scripts for every executed DDL change (if not reversible, the swap strategy must take effect).
  • Communication plan for merchants and partners in case longer recovery is required.

Roles and responsibilities during migrations

  • Software operators: planning, execution, monitoring, final decision on rollout/rollback.
  • Merchants: recipients of information; verify whether creatives or tracking links are affected.
  • Affiliate partners: guidance on expected system stability; actively test if tracking links or parameters change.

Practical runbook (short version)

  1. Secure snapshot + binlog position.
  2. Successfully validate staging migration.
  3. Start online schema change/shadow build (monitoring ON).
  4. Canary deploy new code with dual-read/write.
  5. Validation: check checksums & tracking test events.
  6. Gradual rollout; final toggle to "new logic".
  7. Complete backfill; remove legacy data only after an observation period.
  8. Document the steps and lessons learned.

Conclusion and practical recommendation

Zero‑downtime upgrades require discipline: small, reversible steps, environment tests and automated monitoring gates. For Affilentra operators this means concretely: prioritize additive DDLs, use shadow-table strategies, introduce dual-write with feature toggles and test rollbacks as a standard process. This ensures that merchants and partners continue to receive reliable tracking and auditable billing during a version change of the PRO/NETWORK edition.

Ready to take the next practical step? Choose an entry and learn how Affilentra installations can support migrations and releases in production-like environments.

Next step

Try Affilentra yourself

A unified platform that transparently brings product delivery, tracking, conversion validation, commission calculation and payout together along clearly separated roles; option for self-hosted installation with a perpetual license without revenue sharing; merchants retain control over products, conditions and creatives; partners receive personal tracking links and an auditable payout history.

Choose an entry