Skip to content

Transfer Service — Bulk Migration & Scheduled Ingestion

Tại Sao Quan Trọng Trong Production

gcloud storage cpgsutil rsync là tools hợp lệ cho small-to-medium transfers. Nhưng khi cần migrate petabytes từ AWS S3, Azure Blob, hay on-premises HDFS sang GCS — hoặc khi cần scheduled incremental sync — Cloud Storage Transfer Service là công cụ đúng. Hiểu cơ chế của nó (managed agents, checksum, bandwidth throttling) giúp design migration plans không gây outage production.


Internal Model

Hai Operational Modes

1. Google-Managed Transfers (Cloud-to-Cloud)

Dành cho transfers giữa cloud providers (AWS S3 → GCS, Azure Blob → GCS, một GCS bucket → bucket khác). Transfer jobs chạy trên Google's own infrastructure — không cần infrastructure của customer.

S3 bucket → [Transfer Service managed infra] → GCS bucket

Vì chạy trên Google infra, không có agent cần deploy. Nhưng cần credentials để access source (AWS access keys, Azure SAS token).

2. Self-Hosted Transfer Agents (On-Premises / HDFS)

Dành cho on-premises data sources: POSIX filesystems, HDFS, hoặc sources không accessible từ Google infra.

Customer deploy Transfer Agents — Docker containers chạy trên on-premises machines hoặc GCE VMs — kết nối outbound đến Transfer Service control plane:

On-prem data

Transfer Agent (Docker container, on-prem)
    ↓ outbound HTTPS (port 443)
Transfer Service Control Plane (Google)

GCS bucket

Không có inbound firewall rules cần mở — agents kết nối outbound chỉ. Có thể scale horizontally bằng cách thêm agents.

Job Anatomy

Một Transfer Job bao gồm:

  • Source: S3 URI, Azure container, GCS bucket, HDFS path, on-prem path
  • Destination: GCS bucket (+ optional path prefix)
  • Transfer options: overwrite behavior, delete source after transfer, file filters
  • Schedule: one-time hoặc recurring (daily/weekly)
  • Logging: Sink cho transfer logs (BigQuery, GCS)

Checksum Và Data Integrity

Transfer Service thực hiện end-to-end data integrity verification:

  1. Tính MD5 checksum của source object trước transfer
  2. Upload sang GCS
  3. GCS verify checksum sau khi receive
  4. Transfer Service compare checksums của source và destination
  5. Nếu mismatch → retry

GCS natively hỗ trợ MD5 và CRC32c checksums. Transfer Service ưu tiên CRC32c (nhanh hơn tính toán ở client) khi cả source và destination đều support.

Incremental vs Full Transfers

Transfer Service hỗ trợ incremental sync thông qua overwrite conditions:

json
{
  "transferSpec": {
    "objectConditions": {
      "lastModifiedSince": "2024-01-01T00:00:00Z",
      "includePrefixes": ["data/2024/"],
      "excludePrefixes": ["data/2024/temp/"]
    },
    "transferOptions": {
      "overwriteObjectsAlreadyExistingInSink": "OVERWRITE_IF_DIFFERENT",
      "deleteObjectsUniqueInSink": false
    }
  }
}

overwriteObjectsAlreadyExistingInSink: OVERWRITE_IF_DIFFERENT so sánh checksums — chỉ overwrite khi source khác destination. Đây là mode cho scheduled sync jobs.


Scheduling & Bandwidth Management

Scheduled Transfers

Transfer jobs có thể scheduled với cron-like expression:

python
# Hàng ngày lúc 2AM UTC
schedule = {
    "scheduleStartDate": {"year": 2024, "month": 1, "day": 1},
    "startTimeOfDay": {"hours": 2, "minutes": 0},
    "repeatInterval": {"seconds": 86400}  # 24 giờ
}

Với recurring jobs, Transfer Service chỉ transfer objects đã thay đổi kể từ lần transfer trước (dựa trên lastModifiedSince tự động set sau mỗi run).

Bandwidth Throttling

Với self-hosted agents, có thể kiểm soát bandwidth:

bash
# Deploy agent với bandwidth limit
docker run \
  -e GOOGLE_APPLICATION_CREDENTIALS=/credentials.json \
  gcr.io/cloud-ingest/tsop-agent:latest \
  --project-id=my-project \
  --creds-file=/credentials.json \
  --max-bandwidth=100MBps  # Giới hạn 100 MB/s per agent

Nhiều agents → parallelism tăng, tổng bandwidth tăng. Giới hạn bandwidth để không saturate on-prem network.

Transfer Rate Và SLA Considerations

Transfer Service không cung cấp SLA về transfer speed hay completion time. Performance phụ thuộc vào:

  • Source throughput (S3 rate limits, on-prem disk speed)
  • Network bandwidth
  • GCS write throughput của destination bucket
  • Number of parallel agents (self-hosted mode)

Estimate transfer time:

Data: 100 TB
Network: 1 Gbps dedicated link
Transfer rate (overhead ~80%): ~800 Mbps ≈ 100 MB/s
Time: 100 TB / 100 MB/s ≈ 1,000,000 s ≈ 11.5 ngày

Với dedicated Interconnect và nhiều agents, throughput scale tốt hơn nhiều.


Common Migration Patterns

Pattern 1: One-Time Migration (S3 → GCS)

Bước 1: Tạo transfer job

python
from google.cloud import storage_transfer

client = storage_transfer.StorageTransferServiceClient()

request = storage_transfer.CreateTransferJobRequest(
    transfer_job={
        "project_id": "my-project",
        "transfer_spec": {
            "aws_s3_data_source": {
                "bucket_name": "source-s3-bucket",
                "aws_access_key": {
                    "access_key_id": "AKID...",
                    "secret_access_key": "SECRET..."
                }
            },
            "gcs_data_sink": {
                "bucket_name": "destination-gcs-bucket",
                "path": "migrated-data/"
            },
            "transfer_options": {
                "overwrite_objects_already_existing_in_sink": "ALWAYS",
                "delete_objects_from_source_after_transfer": False
            }
        },
        "status": "ENABLED"
    }
)
job = client.create_transfer_job(request)

Bước 2: Monitor progress qua Operations API hoặc Cloud Monitoring metrics (storagetransfer.googleapis.com/job/*).

Bước 3: Verify integrity — query transfer logs trong BigQuery để check cho failed objects.

Pattern 2: Ongoing Sync (Scheduled Incremental)

Dùng cho scenarios: on-prem → GCS backup, cross-region replication cho DR, archive từ production S3 sang GCS cold storage.

json
{
  "transferSpec": {
    "gcsDataSource": { "bucketName": "prod-bucket" },
    "gcsDataSink": {
      "bucketName": "dr-bucket-us-east",
      "path": "dr-copy/"
    },
    "transferOptions": {
      "overwriteObjectsAlreadyExistingInSink": "OVERWRITE_IF_DIFFERENT",
      "deleteObjectsUniqueInSink": false
    }
  },
  "schedule": {
    "scheduleStartDate": { "year": 2024, "month": 1, "day": 1 },
    "startTimeOfDay": { "hours": 0, "minutes": 0 },
    "repeatInterval": { "seconds": 3600 }
  }
}

Transfer Service vs gsutil vs Storage API Direct

Use CaseTool
< 1TB, interactivegcloud storage cp -r
Large scale cloud-to-cloudTransfer Service
On-premises > 1TBTransfer Service + agents
Custom logic / filteringStorage API trực tiếp + Dataflow
Continuous stream ingestionPub/Sub + Cloud Functions

Constraints & Limitations

Không Có SLA

Transfer Service không cam kết thời gian hoàn thành. Với migrations lớn, luôn có buffer time và plan cutover window.

Source Rate Limits

AWS S3 có rate limits (5,500 GET/s per prefix). Nếu source S3 bucket có ít prefixes, Transfer Service bị throttle. Solution: prefixes phân tán hoặc request S3 rate limit increase trước migration.

VPC-SC Interaction

Nếu destination GCS bucket trong VPC-SC perimeter, phải whitelist Transfer Service service account:

service-PROJECT_NUMBER@gcp-sa-datatransfer.iam.gserviceaccount.com

Add vào ingress rules của perimeter với quyền storage.objects.create trên destination bucket.


References