Skip to main content

Routine Load Principles and Best Practices

Prerequisites and cost​

Use a warehouse SQL user with the required load privileges and an accessible Kafka source. Create and inspect the job in the selected cluster. See Routine Load for setup, security, and parameter limits. Routine Load continuously consumes cluster resources. Pause or stop test jobs when finished, and retain Kafka messages long enough to cover outages and backlog recovery.

Overview​

Routine Load continuously consumes data from Kafka and writes it into VeloDB Cloud. By creating a Routine Load Job, you can automatically subscribe to a specified Kafka topic. Its core features include:

  • High availability: Retries eligible failures and can resume consumption after recovery. Some pause reasons require your intervention.
  • Low latency: Batch settings and available capacity determine when consumed messages become visible.
  • Exactly Once semantics: Commits Kafka offsets with task transactions to avoid duplicate commits when tasks retry. This does not recover expired Kafka messages or deduplicate repeated business events.

Recommended reading paths:

  1. To understand the working mechanism, read Implementation Principles.
  2. To optimize performance, read Best Practices.
  3. To troubleshoot issues, read Common Troubleshooting.

Implementation principles​

Kafka data exists as a stream, and VeloDB Cloud consumes Kafka streaming data in a "micro-batch" manner. After a Routine Load Job is created, the system splits it into multiple Tasks for concurrent execution based on the configured concurrency. Each Task is responsible for consuming data from specific partitions of the Kafka topic. Each Task corresponds to a transaction, and after execution completes, a new Task is generated to continue consuming the next batch of data.

The following sections cover three dimensions:

  • The scheduling mechanism for Jobs and Tasks
  • How Exactly Once semantics are implemented
  • The execution flow for one-stream-multi-table writing

Job and task scheduling​

Routine Load adopts a two-level scheduling model:

Scheduling LevelResponsibility
Job schedulingResponsible for task splitting, failure recovery, and lifecycle management
Task schedulingResponsible for dispatching the actual data fetching, transformation, and writing operations to BE nodes for execution

Job scheduling​

Job state machine

StateMeaning
NEED_SCHEDULEWaiting for the first scheduling or needs to be rescheduled
RUNNINGConsuming normally
PAUSEDPaused either actively or due to an exception, can auto-resume
CANCELLEDTerminated due to unrecoverable errors such as the database or table being dropped
STOPPEDManually stopped and cannot be recovered

Scheduling behavior

In each scheduling cycle, the scheduling thread performs the following actions based on the Job state:

  • NEED_SCHEDULE: Fetches topic metadata (number of partitions, starting offsets), splits Tasks according to the following formula, and places them into needScheduleTasksQueue to wait for the Task scheduling thread to start scheduling them:

    taskNum = min(topic_partition_num,
    desired_concurrent_number,
    max_routine_load_task_concurrent_num)
  • RUNNING: Periodically fetches topic metadata, and immediately reschedules if the number of partitions changes.

  • PAUSED: To ensure high availability of the Job, an auto-resume mechanism is introduced. In the case of an unexpected pause, the Routine Load Scheduler thread attempts to automatically resume the Job. For unexpected Kafka downtime or other situations where Kafka cannot work, eligible jobs can resume after Kafka recovers without manual intervention. Note that there are three situations where the Job will not auto-resume:

    1. The user manually executes the PAUSE ROUTINE LOAD command (MANUAL_PAUSE_ERR).
    2. The pause reason is too many failed rows (TOO_MANY_FAILURE_ROWS_ERR).
    3. The pause reason is not resumable (CANNOT_RESUME_ERR). Dropping a target can also cancel the job.

    Other eligible pause reasons are retried with backoff. Check the actual pause reason and correct persistent source failures before resuming.

  • CANCELLED / STOPPED: Resources are reclaimed with a delay.

Task scheduling​

Scheduling conditions

Task scheduling requires meeting one of the following conditions:

  • The Task has not yet read to the end of the partition, meaning there is still data to consume, to avoid wasting resources.
  • If the previous run already read to EOF, the time since the last execution started must exceed max_batch_interval before a new round of scheduling is initiated. The purpose is to accumulate batches appropriately when consumption speed exceeds production speed, preventing too many small transactions from being generated.

Load balancing strategy

The scheduler selects BE nodes to execute Tasks in the following order:

  1. Prefer BEs that are currently running the fewest Tasks.
  2. If multiple BEs have the same Task count, prefer nodes that have a cached Kafka Consumer to reduce initialization overhead.

Batch boundary

For the batch boundaries below, the task completes its current batch when a configured threshold is reached or it reaches the current Kafka end offset:

  • The time defined by max_batch_interval is reached.
  • The number of rows defined by max_batch_rows is reached.
  • The byte size defined by max_batch_size is reached.
  • Kafka EOF is read, meaning consumption reaches the end of the stream.

After a Task ends, the transaction is committed, and a new Task is immediately generated and placed into the queue to wait for the next scheduling, achieving continuous consumption.

Exactly once semantics​

Routine Load coordinates committed Kafka progress with task transaction checks to avoid duplicate commits during retries. Data availability still depends on Kafka retention, source offsets, and filtering settings.

Persist consumption progress​

In VeloDB Cloud, task transaction commits carry Kafka consumption progress through the metadata service. The job retrieves committed progress during recovery. This differs from the self-managed FE Edit Log and Berkeley DB JE transaction-progress path.

Verify task commits​

When a Job is rescheduled due to manual pause, master switching, or topic metadata changes, two Tasks may briefly consume the same partition concurrently. To prevent duplicate writes:

  • Each Job maintains routineLoadTaskInfoList in memory.
  • Before committing, a Task verifies that it is still in routineLoadTaskInfoList; otherwise, the commit is rejected.

One-stream-multi-table writing​

One-stream-multi-table is used to write to multiple target tables simultaneously from a single Routine Load Job. The core flow is as follows:

  1. Planning phase: Because target tables cannot be fully determined when the Job is created, the execution plan is deferred to runtime, where the BE dynamically requests it from the FE Master.
  2. Data caching: The BE first caches data in a local multi-table pipe. When the service-managed record or unplanned-table threshold is reached, the BE initiates an execution plan request and executes it, preventing data backlog.
  3. Execution plan reuse: Within the same transaction, cached execution plans are reused, while new plans are requested between transactions to ensure metadata freshness.

Best practices​

Start with the job defaults, then tune based on observed Kafka lag, latency, and cluster utilization. The checked Core 26.1.3 implementation uses 60 seconds as the default max_batch_interval. Inspect the actual job properties with SHOW ROUTINE LOAD:

ScenarioRecommended Parameter Changes
Low-latency requirementsReduce max_batch_interval from the default 60s
Small data volume, resource-sensitiveReduce desired_concurrent_number
High throughputIncrease max_batch_interval from the default 60s to 120-180s

Common troubleshooting​

Data backlog​

Follow these three steps to identify the cause of data backlog and optimize:

Step 1: Check task status

Use SHOW ROUTINE LOAD\G to check Task status, focusing on:

  • Whether State is RUNNING. If it is in another state, check the ReasonOfStateChanged field for the reason.
  • Whether there is any error message in OtherMsg.

Step 2: Identify the batch boundary

Compare job statistics and Kafka lag with the configured batch thresholds. If you need task-level diagnostics, ask VeloDB Cloud support to inspect service logs. In the following upstream diagnostic example, the left_time / left_rows / left_bytes values show which threshold was triggered first, so you can correspondingly increase max_batch_size or max_batch_rows:

consumer group done: 894fc32d5b9d3e93-7387a02da6dafd88. consume time(ms)=34004, received rows=2679540, received bytes=2147484043, eos: 0, left_time: 25996, left_rows: 17320460, left_bytes: -395, blocking get time(us): 949236, blocking put time(us): 28730419, id=69616a41fc064f1e-a93ff0ddd217f0a0, job_id=48121487, txn_id=61763720, label=ods_hq_market_unique_jobs_0-48121487-69616a41fc064f1e-a93ff0ddd217f0a0-61763720, elapse(s)=34

In the example above, left_bytes: -395 indicates that the batch ended within 34 seconds because max_batch_size reached its limit. In this case, you can increase max_batch_size appropriately so that a single batch is loaded as fully as possible within max_batch_interval, improving throughput.

Step 3: Increase concurrency and throughput

  • Increase desired_concurrent_number gradually, bounded by the topic partition count and service concurrency limits. More tasks can increase memory and compute consumption.
  • Moderately increase max_batch_interval (such as 120s to 180s), max_batch_size, or max_batch_rows to enlarge the data volume per transaction, increase the data volume per batch, and reduce transaction overhead.

Task unexpectedly paused​

Routine Load has a built-in auto-resume mechanism, and most unexpected pauses are retried. If a Task remains in PAUSED and cannot auto-resume, run SHOW ROUTINE LOAD and investigate in the following directions:

  • Whether PAUSE ROUTINE LOAD was manually executed.
  • Whether there are data quality issues (such as format errors or missing fields).
  • Whether the Kafka data has expired, with an out of range error.

FAQ​

Q1: How does Routine Load guarantee Exactly Once semantics?

Task commits carry Kafka progress through the Cloud metadata service. Task-membership validation rejects stale task commits. These mechanisms protect transaction retries, but do not recover messages already deleted by Kafka retention or deduplicate business events that appear at different offsets.

Q2: Will a Job in PAUSED state auto-resume?

Most unexpected pauses will auto-resume. However, the following three situations will not auto-resume: manually executing PAUSE ROUTINE LOAD, data quality issues, and unrecoverable errors such as the database or table being dropped.

Q3: What determines the number of Tasks?

It is determined by the following formula: taskNum = min(topic_partition_num, desired_concurrent_number, max_routine_load_task_concurrent_num).

Q4: When should max_batch_interval be increased?

In high-throughput scenarios, increasing it from the default 60s to 120s-180s allows for a larger data volume per transaction, reducing transaction overhead and improving overall throughput.

Q5: What does the out of range error in the log mean?

It means the data to be consumed in Kafka has expired (cleaned up by the Kafka retention policy), causing the consumption offset to become invalid. You need to check the Kafka topic's retention period, or reset the starting offset for Routine Load consumption.