Skip to Content
流式数据在实时人工智能应用中的应用
book

流式数据在实时人工智能应用中的应用

by Blaize Stewart, Bipin Singh
August 2025
Beginner to intermediate
52 pages
29m
Chinese
O'Reilly Media, Inc.
Content preview from 流式数据在实时人工智能应用中的应用

第 2 章. 实时数据作为应用架构的一部分

本作品已使用人工智能进行翻译。欢迎您提供反馈和意见:translation-feedback@oreilly.com

现代应用程序在动态数据生态系统中运行,需要实时处理和操作。传统的同步模型难以满足不断增长的数据和延迟需求,导致实时数据管道的兴起。这些管道实现了异步通信、高吞吐量事件处理以及跨分布式系统的一致性。主要架构包括微服务、模块化单体和无服务器。每种架构都能有效地使用实时数据,但也有不同的取舍。

微服务架构

微服务架构是一种设计范式,它将应用程序分解为一系列独立的小型服务,每个服务负责特定的功能。

微服务套件中的服务传统上使用 HTTP 或 gRPC 等轻量级协议通过网络进行通信。这种通信依赖于同步请求-响应机制和服务对服务的直接调用,但它会造成瓶颈,从而增加复杂性并降低弹性。为了应对这些挑战,许多企业转向消息代理,通过消息传递和事件流进行异步通信,而不是直接调用 API。通过事件驱动消息传递,服务可自主运行,在事件到达时进行处理。流管道的骨干建立在 Apache Kafka、Redpanda、Apache Pulsar、Google Pub/Sub 等事件流平台以及 Azure Event Hubs 和 Amazon Kinesis 等云服务提供商的解决方案之上。1

有两种常见的应用模式与微服务一起使用,通过代理管理解耦,这两种模式经常一起使用:事件源 和命令查询责任隔离(CQRS)。

CQRS 将读取和写入操作分离成不同的模型,以便针对各自特定的工作负载进行优化。CQRS 引入了两个专门组件,而不是强迫一个数据库处理所有操作。第一个是命令模型,负责处理写入和更新。该模型通常与事件源协同工作,将变更存储为不可变事件,而不是直接更新数据库。第二种是查询模型,它针对快速高效的读取进行了优化。2图 2-1描述了 CQRS 应用模式。

A diagram of a process

AI-generated content may be incorrect.
图 2-1. CQRS

事件源可与 CQRS 配合使用。通过事件源,应用程序状态的每次变化都会被记录为不可变事件,而不是更新和覆盖数据库中的记录。这些事件形成了系统中发生的所有事件的历史记录(类似于分类账)。3

人工智能以几种不同的方式集成并增强了 CQRS 和事件源:

  • 人工智能驱动的分析可以处理存储在事件源系统中的历史事件日志,以检测模式、异常和趋势,为业务决策提供依据。

  • 在 CQRS 中,人工智能模型可根据用户行为动态生成预测见解和个性化数据检索,从而优化查询模型。

  • 人工智能驱动的自动化可以智能地确定事件的优先级、减少噪音并确保关键更新在系统中高效传播,从而增强数据管道。

  • 机器学习模型还能预测微服务工作流中的潜在故障或瓶颈,从而提高弹性。

采用微服务会带来挑战。CQRS 和事件源尤其如此,它们引入了最终一致性,这意味着系统的各个部分可能并不总是一致的。确保消息排序和重复数据删除至关重要,因为在快节奏的系统中,无序或重复的事件可能会导致错误。可观察性也很复杂,需要使用 OpenTelemetry 或 Jaeger 等工具来跟踪跨服务的事件。在操作上,微服务需要强大的服务发现、API 网关、分布式日志记录和无缝部署,以处理频繁的更新。尽管如此,微服务在可扩展性、高可用性环境(如网络应用程序、云原生系统和软件即服务(SaaS)平台)中表现出色。 ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

快速提升人工智能产品的实用指南

快速提升人工智能产品的实用指南

Hamel Husain

Publisher Resources

ISBN: 9798341666511