Mantieni tutto organizzato con le raccolte
Salva e classifica i contenuti in base alle tue preferenze.
Dataflow supporta due modalità per i job di streaming:
Modalità exactly-once. Questa modalità è quella predefinita per tutti i job Dataflow di streaming. In questa modalità, Dataflow
garantisce che i record non vengano eliminati o duplicati man mano che i dati si spostano
nella pipeline.
Modalità at-least-once. Questa modalità garantisce che i record vengano elaborati almeno una volta (ovvero, nessun record di input viene perso). Tuttavia, in questa modalità sono possibili record duplicati. Per i casi d'uso che possono tollerare i duplicati,
la modalità almeno una volta può ridurre significativamente il costo e la latenza del job.
Scegliere la modalità di streaming da utilizzare
Scegli la modalità exactly-once se devi garantire risultati esatti dalla pipeline
e una semantica prevedibile. Ad esempio:
Pipeline con
aggregazioni,
come conteggio, somma o media.
Casi d'uso business-critical che si basano sull'elaborazione dei record una sola volta. Alcuni esempi sono il rilevamento di frodi, il rilevamento di minacce alla rete e
le dashboard dell'inventario dell'e-commerce.
Scegli la modalità di streaming almeno una volta se il tuo workload può tollerare record duplicati e potrebbe trarre vantaggio da costi o latenza ridotti. Ad esempio:
Carichi di lavoro in cui la deduplicazione viene eseguita a valle di
Dataflow. Ad esempio, pipeline che scrivono in
BigQuery o in un datastore SQL.
Pipeline solo mappa senza aggregazioni. Alcuni esempi includono l'elaborazione dei log, la
capturing dei dati modificati o i job di estrazione, trasformazione e caricamento (ETL), in cui la
pipeline esegue solo trasformazioni per elemento, come la traduzione dello schema.
Pipeline in cui il sink di output non può garantire la consegna "exactly-once", ad esempio Pub/Sub. In questo caso, la deduplicazione all'interno della pipeline potrebbe
essere non necessaria e puoi usufruire del costo e della latenza ridotti della
modalità di streaming almeno una volta.
Pipeline che leggono i dati da Pub/Sub. La lettura da Pub/Sub è
notevolmente ottimizzata quando si utilizza la modalità at-least-once.
Ulteriori considerazioni
La modalità almeno una volta può ridurre notevolmente il costo e la latenza di una pipeline. L'impatto esatto dipende dalle specifiche della pipeline. Testa
lo streaming at-least-once in condizioni di carico realistiche per valutare l'impatto.
Quando utilizzi la modalità almeno una volta, la frequenza dei record duplicati dipende dal
numero di tentativi. Il tasso di base è in genere basso (< 1%). Tuttavia, possono verificarsi picchi
se i nodi di lavoro non funzionano o se altre condizioni causano chiamate RPC ripetute.
La modalità di streaming influisce sul modo in cui Streaming Engine elabora i record, ma non modifica la semantica dei connettori I/O. Ti consigliamo di allineare la semantica I/O alla modalità di streaming. Ad esempio, se utilizzi la modalità di streaming
at-least-once con il
connettore BigQuery I/O,
imposta la modalità di scrittura su STORAGE_API_AT_LEAST_ONCE.
I modelli Dataflow forniti da Google
attivano automaticamente questa opzione quando utilizzi lo streaming almeno una volta.
Le trasformazioni elemento per elemento come Map non sono sempre idempotenti. Ad esempio,
considera una funzione che riceve un messaggio e aggiunge il timestamp corrente. In questo caso, un record duplicato può produrre diversi output distinti.
La modalità "Almeno una volta" potrebbe non essere appropriata per questa pipeline.
Impostare la modalità di streaming
L'elaborazione "exactly-once" è l'impostazione predefinita per tutti i job Dataflow. Per attivare la modalità flusso di dati Almeno una volta, imposta l'opzione di serviziostreaming_mode_at_least_once.
Queste due opzioni si escludono a vicenda. Se non imposti una di queste opzioni, il modello utilizza per impostazione predefinita una modalità di streaming determinata dai metadati del modello. Per ulteriori informazioni, consulta
Modelli personalizzati.
Se crei un modello personalizzato che supporta l'elaborazione almeno una volta, aggiungi i
seguenti campi di primo livello al file dei metadati del modello:
Questi campi di metadati consentono agli utenti di selezionare la modalità di streaming durante il deployment
del modello nella console Google Cloud . Il campo defaultStreamingMode
è facoltativo e specifica la modalità di streaming predefinita per il modello. Se non specifichi defaultStreamingMode e il modello supporta entrambe le modalità, la modalità esattamente una volta è quella predefinita.
Per ulteriori informazioni, consulta le seguenti sezioni della documentazione sui modelli Dataflow:
La modalità almeno una volta utilizza sempre la fatturazione basata sulle risorse, in cui ti viene addebitato il costo delle risorse totali consumate dal job.
Il costo per unità delle
unità di calcolo Streaming Engine è
lo stesso indipendentemente dalla modalità di streaming. Tuttavia, nella maggior parte dei casi una pipeline
consuma molte meno risorse totali quando utilizza la modalità almeno una volta.
[[["Facile da capire","easyToUnderstand","thumb-up"],["Il problema è stato risolto","solvedMyProblem","thumb-up"],["Altra","otherUp","thumb-up"]],[["Difficile da capire","hardToUnderstand","thumb-down"],["Informazioni o codice di esempio errati","incorrectInformationOrSampleCode","thumb-down"],["Mancano le informazioni o gli esempi di cui ho bisogno","missingTheInformationSamplesINeed","thumb-down"],["Problema di traduzione","translationIssue","thumb-down"],["Altra","otherDown","thumb-down"]],["Ultimo aggiornamento 2025-09-04 UTC."],[[["\u003cp\u003eDataflow supports two streaming modes: exactly-once, which ensures no data is lost or duplicated, and at-least-once, which guarantees no data loss but may result in duplicates.\u003c/p\u003e\n"],["\u003cp\u003eExactly-once mode is the default for all Dataflow streaming jobs and is recommended for pipelines requiring precise results, such as those involving aggregations or business-critical applications like fraud detection.\u003c/p\u003e\n"],["\u003cp\u003eAt-least-once mode can significantly reduce costs and latency and is suitable for workloads that can tolerate duplicate records, such as those with downstream deduplication or map-only pipelines.\u003c/p\u003e\n"],["\u003cp\u003eThe choice of streaming mode affects how Streaming Engine processes data but does not alter the semantics of I/O connectors; it is recommended to use the right connector to complement the streaming mode.\u003c/p\u003e\n"],["\u003cp\u003eYou can set at-least-once streaming mode using the \u003ccode\u003estreaming_mode_at_least_once\u003c/code\u003e service option in Java, Python, Go, console, or via the REST API, and it will be automatically applied in Dataflow templates when they support it.\u003c/p\u003e\n"]]],[],null,["# Set the pipeline streaming mode\n\nDataflow supports two modes for streaming jobs:\n\n- **Exactly-once mode**. This mode is the default for all Dataflow streaming jobs. In this mode, Dataflow ensures that records are not dropped or duplicated as the data moves through the pipeline.\n- **At-least-once mode**. This mode guarantees that records are processed at least once (that is, no input records are lost). However, duplicate records are possible in this mode. For use cases that can tolerate duplicates, at-least-once mode can significantly lower the cost and latency of your job.\n\nChoose which streaming mode to use\n----------------------------------\n\nChoose exactly-once mode if you need to ensure exact results from the pipeline\nand predictable semantics. For example:\n\n- Pipelines with [aggregations](https://beam.apache.org/documentation/basics/#aggregation), such as count, sum, or mean.\n- Business-critical use cases that rely on records being processed once and only once. Examples include fraud detection, network threat detection, and ecommerce inventory dashboards.\n\nChoose at-least-once streaming mode if your workload can tolerate duplicated\nrecords and might benefit from reduced cost or latency. For example:\n\n- Workloads where deduplication is performed downstream from Dataflow. For example, pipelines that write to BigQuery or a SQL datastore.\n- Map-only pipelines with no aggregations. Examples include log processing, change data capture, or extract, transform, and load (ETL) jobs, in which the pipeline performs only per-element transforms, such as schema translation.\n- Pipelines where the output sink can't guarantee exactly-once delivery, such as Pub/Sub. In that case, deduplication *within* the pipeline might be unnecessary, and you can benefit from the reduced cost and latency of at-least-once streaming mode.\n- Pipelines that read from Pub/Sub. Reading from Pub/Sub is significantly optimized when using at-least-once mode.\n\n### Additional considerations\n\n- At-least-once mode can significantly reduce the cost and latency of a\n pipeline. The exact impact depends on the specifics of the pipeline. Test\n at-least-once streaming under realistic loads to evaluate the impact.\n\n- When using at-least-once mode, the rate of duplicate records depends on the\n number of retries. The baseline rate is typically low (\\\u003c1%). However, spikes\n can occur if worker nodes fail or other conditions cause repeated RPC calls.\n\n- The streaming mode affects how Streaming Engine processes records, but does\n not change the semantics of I/O connectors. It is recommended to align your\n I/O semantics with the streaming mode. For example, if you use at-least-once\n streaming mode with the\n [BigQuery I/O connector](/dataflow/docs/guides/write-to-bigquery),\n set the write mode to `STORAGE_API_AT_LEAST_ONCE`.\n [Google-provided Dataflow templates](/dataflow/docs/guides/templates/provided-templates)\n automatically enable this option when you use at-least-once streaming.\n\n- Element-wise transforms such as `Map` are not always idempotent. For example,\n consider a function that receives a message and appends the current timestamp\n to it. In that case, a duplicate record can produce several distinct outputs.\n At-least-once mode might not be appropriate for that pipeline.\n\nSet the streaming mode\n----------------------\n\nExactly-once processing is the default setting for all Dataflow\njobs. To enable at-least-once streaming mode, set the\n`streaming_mode_at_least_once`\n[service option](/dataflow/docs/reference/service-options). \n\n### Java\n\n --dataflowServiceOptions=streaming_mode_at_least_once\n\n### Python\n\n --dataflow_service_options=streaming_mode_at_least_once\n\n### Go\n\n --dataflow_service_options=streaming_mode_at_least_once\n\nIf you don't specify the `streaming_mode_at_least_once` option, then\nDataflow uses exactly-once streaming mode.\n\nIf you set the `streaming_mode_at_least_once` option, Dataflow\nautomatically enables [Streaming Engine](/dataflow/docs/streaming-engine) with\n[resource-based billing](/dataflow/docs/streaming-engine#compute-unit-pricing).\n\nTo update the streaming mode on a running job,\n[launch a replacement job](/dataflow/docs/guides/updating-a-pipeline#Launching).\n\nSelect the streaming mode for a template\n----------------------------------------\n\nTo select the streaming mode when you run a Dataflow streaming\ntemplate, perform the following steps: \n\n### Console\n\n1. In the Google Cloud console, go to the Dataflow **Jobs**\n page.\n\n [Go to Jobs](https://console.cloud.google.com/dataflow/jobs)\n2. Click **Create job from template**.\n\n3. Select the template that you want to run from the\n **Dataflow template** drop-down menu.\n\n4. For **Streaming mode**, select the streaming mode. If the template supports\n only one mode, then this option is disabled.\n\n### gcloud\n\nTo enable at-least-once mode, set the `streaming_mode_at_least_once` option\nin the `additional-experiments` flag: \n\n --additional-experiments=streaming_mode_at_least_once\n\nTo enable exactly-once mode, set the `streaming_mode_exactly_once` option\nin the `additional-experiments` flag: \n\n --additional-experiments=streaming_mode_exactly_once\n\nThese two options are mutually exclusive. If you don't set one of these\noptions, then the template defaults to a streaming mode that is determined by\nthe template metadata. For more information, see\n[Custom templates](#custom-templates).\n\n### REST\n\nUse the `additionalExperiments` field in the\n[`FlexTemplateRuntimeEnvironment`](/dataflow/docs/reference/rest/v1b3/projects.locations.flexTemplates/launch#FlexTemplateRuntimeEnvironment)\n(Flex templates) or\n[`RuntimeEnvironment`](/dataflow/docs/reference/rest/v1b3/RuntimeEnvironment)\n(classic templates) object. \n\n {\n additionalExperiments : [\"streaming_mode_at_least_once\"]\n ...\n }\n\n### Custom templates\n\nIf you create a custom template that supports at-least-once processing, add the\nfollowing top-level fields to the template metadata file: \n\n {\n \"streaming\": true,\n \"supportsAtLeastOnce\": true,\n \"supportsExactlyOnce\": true,\n \"defaultStreamingMode\": \"AT_LEAST_ONCE\"\n }\n\nThese metadata fields enable users to select the streaming mode when deploying\nthe template in the Google Cloud console. The `defaultStreamingMode` field\nis optional and specifies the default streaming mode for the template. If you\ndon't specify `defaultStreamingMode` and the template supports both modes, then\nexactly-once mode is the default.\n\nFor more information, see the following sections in the Dataflow\ntemplates documentation:\n\n- Flex templates: [Metadata](/dataflow/docs/guides/templates/configuring-flex-templates#metadata)\n- Classic templates: [Use metadata in your pipeline code](/dataflow/docs/guides/templates/creating-templates#use-metadata-in-your-pipeline-code)\n\nView a job's streaming mode\n---------------------------\n\nTo view the streaming mode for a job, go to the **Jobs** page in the\nGoogle Cloud console.\n\n[Go to Jobs](https://console.cloud.google.com/dataflow/jobs)\n\nThe streaming mode is also listed on the job details page, in the **Job\ninfo** panel.\n\nLimitations\n-----------\n\nAt-least-once streaming mode requires\n[Streaming Engine](/dataflow/docs/streaming-engine) with\n[resource-based billing](/dataflow/docs/streaming-engine#compute-unit-pricing).\n\nPricing\n-------\n\nAt-least-once mode always uses\n[resource-based billing](/dataflow/docs/streaming-engine#compute-unit-pricing),\nwhere you're billed for the total resources that are consumed by your job.\n\nThe per-unit cost of\n[Streaming Engine Compute Units](/dataflow/pricing#streaming-compute-units) is\nthe same regardless of the streaming mode. However, in most cases a pipeline\nconsumes significantly fewer total resources when using at-least-once mode.\n\nWhat's next\n-----------\n\n- Learn more about [exactly-once processing](/dataflow/docs/concepts/exactly-once)."]]