Media Processing & Recovery

Unified Media Ledger Architecture (Sync vs Async Mode)

Complete architectural reference for media status tracking, SHA-256 deduplication, and database persistence across execution modes.

Frexten Engineering Team
Updated 2026-11-20

Article Overview

  • Category: Media Processing, Data Architecture & Server Reliability
  • Audience: Store Owners, DevOps Engineers, Technical Support & WordPress Developers
  • Applies To: NextGen Smart Data Importer (Community Free & Enterprise Pro Editions)
  • Purpose: Technical guide, architecture documentation, and customer knowledge base explaining media status tracking across execution modes.

1. Executive Summary

When importing thousands of records containing remote images (e.g. WooCommerce product galleries, featured images, and author avatars), media processing is typically the most time-consuming and network-sensitive phase of data migration.

NextGen Smart Data Importer supports two distinct media execution modes:

  1. Synchronous Mode (On-The-Fly): Images are resolved, downloaded, and sideloaded immediately as each data row is processed during the import request.
  2. Asynchronous Mode (Background Queue): Image URLs are decoupled from post creation and pushed into a dedicated queue table (wp_nextgen_image_queue), where a background cron worker downloads and links them in micro-batches without blocking the main import thread.

To ensure 100% auditability, reliability, and error transparency, NextGen employs a Unified Media Ledger Architecture. Both synchronous and asynchronous imports record their lifecycle states (completed, reused, failed, and pending) into the same database table, providing site administrators with a single, queryable source of truth.


2. Architecture & Data Flow

Architecture Flowchart
flowchart TD Row["Data Row with Image URL
(featured_image, product_gallery)"] --> Mode{"Media Execution Mode?"} subgraph Async["Asynchronous Mode (Pro Enterprise)"] AsyncInsert["1. Insert into nextgen_image_queue
(status: 'pending')"] AsyncReturn["2. Post Created Immediately
(Returns simulated queued state)"] CronWorker["3. Background Cron Worker
(NextGen_Image_Processor)"] CronFetch["4. Download & Sideload in Micro-Batches"] CronUpdate["5. Update nextgen_image_queue
(status: 'completed', 'reused', or 'failed')"] end subgraph Sync["Synchronous Mode (Free & Pro Baseline)"] SyncCheck["1. Fast Check & Turbo Hash Check
(If match: status = 'reused')"] SyncDownload["2. Download External Image
(Multi-tier: download_url → stream → cURL)"] SyncSideload["3. media_handle_sideload & Link Post"] SyncRecord["4. Record into nextgen_image_queue
(status: 'completed' or 'failed')"] end Mode -- "Async Enabled" --> AsyncInsert AsyncInsert --> AsyncReturn AsyncInsert --> CronWorker CronWorker --> CronFetch CronFetch --> CronUpdate Mode -- "Synchronous" --> SyncCheck SyncCheck --> SyncDownload SyncDownload --> SyncSideload SyncSideload --> SyncRecord CronUpdate --> UnifiedTable[("🏆 Unified nextgen_image_queue Ledger
• Full Historical Audit
• Real-Time Failure Visibility
• 1-Click Retry Capability")] SyncRecord --> UnifiedTable

3. Database Schema: wp_nextgen_image_queue

Both execution modes record into the dedicated wp_nextgen_image_queue table:

sql
CREATE TABLE wp_nextgen_image_queue (
    id bigint(20) NOT NULL AUTO_INCREMENT,
    import_id varchar(100) NOT NULL,
    post_id bigint(20) NOT NULL,
    image_url longtext NOT NULL,
    original_url longtext DEFAULT NULL,
    filename_hint varchar(255) DEFAULT NULL,
    image_type varchar(50) NOT NULL,
    media_meta longtext DEFAULT NULL,
    status varchar(50) DEFAULT 'pending' NOT NULL,
    error_msg longtext DEFAULT NULL,
    created_at datetime DEFAULT CURRENT_TIMESTAMP NOT NULL,
    PRIMARY KEY  (id),
    KEY import_id (import_id),
    KEY status (status)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

Field Definitions:

  • import_id: Links the media operation to the specific import session for session-level reporting and rollback.
  • post_id: The target entity (post, product, page) to which the image is attached.
  • image_url: The effective, resolved target URL.
  • original_url: The raw URL provided in the source CSV/XML/Excel file.
  • filename_hint: The sanitized filename computed from query parameters, path segments, or URL hash.
  • image_type: The attachment role (featured, gallery, inline).
  • media_meta: JSON-encoded metadata (ALT text, Title, Caption, Description).
  • status: The lifecycle state of the image:
    • pending: Awaiting background cron download (Async mode only).
    • completed: Successfully downloaded, sideloaded, and linked.
    • reused: Identified an existing media file via MD5 hash or filename collision check; skipped download to save bandwidth and storage.
    • failed: Download or sideload encountered an error; the specific reason is stored in error_msg.
  • error_msg: Captured human-readable error (e.g. 404 Not Found, A valid URL was not provided, cURL error 28: Operation timed out).

4. The 4 Core Advantages of Capturing Status in Both Modes

1. Single Source of Truth & 100% Auditability

Without synchronous status capture, media history is fractured: background imports log structured rows in MySQL, while synchronous imports only leave transient lines in a text log file (server.log).

With the Unified Media Ledger:

  • Every single image attempted during the import lifecycle is permanently cataloged in the database.
  • Administrators can run structured queries or view in-app reports showing the exact breakdown of media operations across any past import session: $$\text{Total Images Processed} = \text{Completed} + \text{Reused} + \text{Failed} + \text{Pending}$$

2. Immediate Failure Visibility (No Log Hunting)

Remote image servers frequently fail during large data migrations:

  • CDN rate limits or Cloudflare challenges.
  • Broken placeholder URLs (e.g. DNS timeout on test mock servers).
  • HTTP 404 / 403 access restrictions.

In traditional importers, finding 4 broken images among a 10,000-product catalog requires combing through a 50MB raw log file. With NextGen's Unified Ledger, a single point lookup reveals all failures instantly:

sql
SELECT post_id, image_url, error_msg 
FROM wp_nextgen_image_queue 
WHERE import_id = 'imp_6619a9f2bc83' AND status = 'failed';

3. One-Click "Retry Failed Images"

Because failed synchronous images have their complete payload preserved in nextgen_image_queue:

  • post_id
  • image_url
  • image_type
  • media_meta (ALT text, caption)
  • error_msg

The system can offer a 1-Click Retry mechanism. Flipping failed records back to status = 'pending' allows the background cron processor to retry downloading and linking them later, without having to re-import or re-map the entire dataset!

sql
UPDATE wp_nextgen_image_queue 
SET status = 'pending', error_msg = NULL 
WHERE import_id = 'imp_6619a9f2bc83' AND status = 'failed';

4. Zero Worker Contention or Cron Conflicts

A common concern with storing synchronous rows in a queue table is whether the background cron worker will accidentally re-download them.

NextGen eliminates this through strict query segmentation:

  • The background cron worker (NextGen_Image_Processor::process_queue()) strictly queries:
sql
SELECT * FROM wp_nextgen_image_queue WHERE status = 'pending' ORDER BY id ASC LIMIT 50
  • Because synchronous rows are written directly with their final status (completed, reused, or failed), the background worker never picks them up. They act as a clean historical audit ledger with zero worker contention.

5. Implementation Reference: download_image()

Inside includes/importer/free/importers/class-nextgen-base-importer.php, the synchronous image handler records the lifecycle state into nextgen_image_queue at every branch:

php
// Helper method to record media audit records
protected function record_media_status($import_id, $post_id, $url, $type, $status, $filename = '', $error_msg = null, $meta = null)
{
    global $wpdb;
    $wpdb->insert($wpdb->prefix . 'nextgen_image_queue', array(
        'import_id'     => $import_id,
        'post_id'       => $post_id,
        'image_url'     => trim($url),
        'original_url'  => trim($url),
        'filename_hint' => $filename,
        'image_type'    => $type,
        'media_meta'    => !empty($meta) ? wp_json_encode($meta) : null,
        'status'        => $status, // 'completed', 'reused', or 'failed'
        'error_msg'     => $error_msg,
        'created_at'    => current_time('mysql'),
    ));
}

Execution Touchpoints:

  1. On Fast/Turbo Check match:
php
$this->record_media_status($this->current_import_id, $post_id, $url, $image_type, 'reused', $filename);
  1. On Sideload Success:
php
$this->record_media_status($this->current_import_id, $post_id, $url, $image_type, 'completed', $sideload_name, null, $media_meta);
  1. On Sideload Failure:
php
$this->record_media_status($this->current_import_id, $post_id, $url, $image_type, 'failed', '', $id->get_error_message());

6. Frequently Asked Questions (FAQ)

Q: Does writing synchronous records to nextgen_image_queue slow down the import?

A: No. Downloading a remote image over HTTP takes between 200ms and 2,000ms. Inserting a single record into an indexed local MySQL table takes 0.05ms to 0.1ms. The performance impact is mathematically negligible (~0.01% of total row execution time).

Q: What happens to nextgen_image_queue records during a 1-Click Rollback?

A: When an import is rolled back, NextGen's rollback engine scans all entities tracked in wp_nextgen_file_records. Any attachment post IDs created during the import are safely deleted from the WordPress media library, and the corresponding queue records for that import_id are purged.

Q: When should a user choose Asynchronous over Synchronous mode?

  • Choose Synchronous Mode: For small imports (<500 images) or when products must display their featured images the exact second the import finishes.
  • Choose Asynchronous Mode (Pro): For large imports (thousands of images), slow remote hosting servers, or when memory conservation and maximum post-creation speed are the primary goals.