Big Data processing architecture and Lambda Kappa architecture

First we look at a typical large Internet data platform architecture, as shown below:

In this architecture diagram, big data platform which indicate to the user's online business processing components with a brown out, this part is part of the Internet for online applications belonging to the other part of the blue part of the big data-related components, the use of open source big data products or develop their own large data-related components.

As you can see, a large internet data from top to bottom, can be divided into three parts: data acquisition, data processing, output and display data.

data collection

The application generates data and log isochronous data to large systems, because different data sources, where the data synchronization system is actually a combination of a plurality of related systems. Database synchronization is usually Sqoop, log synchronization to select Flume, Logging data format after converted to be transmitted through the message queue Kafka the like.

The quality of the data produced by different data sources may vary widely, data in the database may be able to directly import large data system is ready for use, and the data generated logs and reptiles need a lot of cleaning, conversion treatment to be used effectively.
data processing

This is the core of large data storage and computing, data synchronization in a data storage system lead HDFS. MapReduce, Hive, Spark other computing tasks to read the data on the HDFS is calculated, and then writes the result to HDFS.

MapReduce, Hive, Spark calculation processing or the like is referred to as off-line computation, data storage is referred to HDFS offline data. Off-line calculation performed on large data systems generally for all data (one aspect of), such as commodity association mining history for all orders, this time the data is very large, it takes a long time to run, such calculations is offline computing.

In addition to off-line computing, there are some scenarios, the data size is relatively large, but requires processing time is relatively short. Such as Taobao To count the number of orders generated per second for monitoring and advocacy. This scenario is referred to as a large data stream is calculated, usually Storm, Spark Steaming other large data stream to complete the engine can be completed within the calculated time of seconds or even milliseconds.

Data output and display

Large data for calculating the resulting data is written to or in HDFS, but the application can not read data to HDFS, so must To export the data into the database in HDFS. Exporting data synchronization is relatively easy to produce calculated data are more standardized, little processing proceeds with the database can be exported to a system Sqoop like.

At this time, the application can access data directly in the database, real-time display to the user, such as displayed to the user associated with recommended products.

In addition to providing data to the user access, large data also need to provide a variety of operational and decision-making statistical reports, data is also written to the database being accessed the appropriate back-end system. Many operators and management personnel, a work every day, is the back-end data systems login to view the previous day's data report, to see whether it is normal business. If the data is normal or even increased, you can relax a little; if the data fall, anxious and busy day is about to begin.

The three parts of the above is to integrate scheduling management system, when different data start synchronization, a variety of MapReduce, Spark how reasonable task scheduling to make the most rational use of resources, time and will not wait too long, while temporary also important tasks can be executed as soon as possible, which requires task scheduling management system to complete.

Mentioned above such large data platform architecture, also known as Lambda architecture, it is to construct a conventional architecture prototype program big data platform. Lambda architecture prototype Look at the following chart.

Lambda architecture

Lambda architecture (Lambda Architecture) is proposed by Twitter engineer Nansen Mats (Nathan Marz) big data processing architecture. This made based on experience and Matz on Twitter BackType distributed data processing system architecture.

Lambda architecture allows developers to build large-scale distributed data processing system. It has good flexibility and scalability, but also has good fault tolerance for hardware failure and human error.

Lambda architecture of a total of three systems: Batch layer (Batch Layer), speed of processing layer (Speed ​​Layer), as well as for the service layer (Serving Layer) in response to queries.

In the Lambda architecture, each layer has its own shouldered the task.

Batch master data set storage management layer (immutable data set) and pre-computed batch view.

批处理层使用可处理大量数据的分布式处理系统预先计算结果。它通过处理所有的已有历史数据来实现数据的准确性。这意味着它是基于完整的数据集来重新计算的,能够修复任何错误,然后更新现有的数据视图。输出通常存储在只读数据库中,更新则完全取代现有的预先计算好的视图。

速度处理层会实时处理新来的大数据。

速度层通过提供最新数据的实时视图来最小化延迟。速度层所生成的数据视图可能不如批处理层最终生成的视图那样准确或完整,但它们几乎在收到数据后立即可用。而当同样的数据在批处理层处理完成后,在速度层的数据就可以被替代掉了。

本质上,速度层弥补了批处理层所导致的数据视图滞后。比如说,批处理层的每个任务都需要 1 个小时才能完成,而在这 1 个小时里,我们是无法获取批处理层中最新任务给出的数据视图的。而速度层因为能够实时处理数据给出结果,就弥补了这 1 个小时的滞后。

所有在批处理层和速度层处理完的结果都输出存储在服务层中,服务层通过返回预先计算的数据视图或从速度层处理构建好数据视图来响应查询。

例如广告投放预测这种推荐系统一般都会用到Lambda架构。一般能做精准广告投放的公司都会拥有海量用户特征、用户历史浏览记录和网页类型分类这些历史数据的。业界比较流行的做法有在批处理层用Alternating Least Squares (ALS)算法,也就是Collaborative Filtering协同过滤算法,可以得出与用户特性一致其他用户感兴趣的广告类型,也可以得出和用户感兴趣类型的广告相似的广告,而用k-means也可以对客户感兴趣的广告类型进行分类。

这里的结果是批处理层的结果。在速度层中根据用户的实时浏览网页类型在之前分好类的广告中寻找一些top K的广告出来。最终服务层可以结合速度层的top K广告和批处理层中分类好的点击率高的相似广告,做出选择投放给用户。

Lambda 架构的不足

虽然 Lambda 架构使用起来十分灵活,并且可以适用于很多的应用场景,但在实际应用的时候,Lambda 架构也存在着一些不足,主要表现在它的维护很复杂。

使用 Lambda 架构时,架构师需要维护两个复杂的分布式系统,并且保证他们逻辑上产生相同的结果输出到服务层中。

我们都知道,在分布式框架中进行编程其实是十分复杂的,尤其是我们还会针对不同的框架进行专门的优化。所以几乎每一个架构师都认同,Lambda 架构在实战中维护起来具有一定的复杂性。

那要怎么解决这个问题呢?我们先来思考一下,造成这个架构维护起来如此复杂的根本原因是什么呢?

维护 Lambda 架构的复杂性在于我们要同时维护两套系统架构:批处理层和速度层。我们已经说过了,在架构中加入批处理层是因为从批处理层得到的结果具有高准确性,而加入速度层是因为它在处理大规模数据时具有低延时性。

那我们能不能改进其中某一层的架构,让它具有另外一层架构的特性呢?

例如,改进批处理层的系统让它具有更低的延时性,又或者是改进速度层的系统,让它产生的数据视图更具准确性和更加接近历史数据呢?

另外一种在大规模数据处理中常用的架构——Kappa 架构(Kappa Architecture),便是在这样的思考下诞生的。

Kappa 架构

Kappa 架构是由 LinkedIn 的前首席工程师杰伊·克雷普斯(Jay Kreps)提出的一种架构思想。克雷普斯是几个著名开源项目(包括 Apache Kafka 和 Apache Samza 这样的流处理系统)的作者之一,也是现在 Confluent 大数据公司的 CEO。

克雷普斯提出了一个改进 Lambda 架构的观点:

我们能不能改进 Lambda 架构中速度层的系统性能,使得它也可以处理好数据的完整性和准确性问题呢?我们能不能改进 Lambda 架构中的速度层,使它既能够进行实时数据处理,同时也有能力在业务逻辑更新的情况下重新处理以前处理过的历史数据呢?

他根据自身多年的架构经验发现,我们是可以做到这样的改进的。

像 Apache Kafka 这样的流处理平台是具有永久保存数据日志的功能的,通过平台的这一特性,我们可以重新处理部署于速度层架构中的历史数据。

下面就以 Apache Kafka 为例来讲述整个全新架构的过程。


及时获取更多大数据技术分享,请关注我的微信公众号《大数据技术进阶》

第一步,部署 Apache Kafka,并设置数据日志的保留期(Retention Period)。这里的保留期指的是你希望能够重新处理的历史数据的时间区间。

例如,如果你希望重新处理最多一年的历史数据,那就可以把 Apache Kafka 中的保留期设置为 365 天。如果你希望能够处理所有的历史数据,那就可以把 Apache Kafka 中的保留期设置为“永久(Forever)”。

第二步,如果我们需要改进现有的逻辑算法,那就表示我们需要对历史数据进行重新处理。

我们需要做的就是重新启动一个 Apache Kafka 作业实例(Instance)。这个作业实例将从头开始,重新计算保留好的历史数据,并将结果输出到一个新的数据视图中。我们知道 Apache Kafka 的底层是使用 Log Offset 来判断现在已经处理到哪个数据块了,所以只需要将 Log Offset 设置为 0,新的作业实例就会从头开始处理历史数据。

第三步,当这个新的数据视图处理过的数据进度赶上了旧的数据视图时,我们的应用便可以切换到从新的数据视图中读取。

第四步,停止旧版本的作业实例,并删除旧的数据视图。

与 Lambda 架构不同的是,Kappa 架构去掉了批处理层这一体系结构,而只保留了速度层。你只需要在业务逻辑改变又或者是代码更改的时候进行数据的重新处理。

在讲述完 Kappa 架构之后,我想强调一下,Kappa 架构也是有着它自身的不足的。

因为 Kappa 架构只保留了速度层而缺少批处理层,在速度层上处理大规模数据可能会有数据更新出错的情况发生,这就需要我们花费更多的时间在处理这些错误异常上面。

还有一点,Kappa 架构的批处理和流处理都放在了速度层上,这导致了这种架构是使用同一套代码来处理算法逻辑的。所以 Kappa 架构并不适用于批处理和流处理代码逻辑不一致的场景。

小结
在本文中,我们简述了 Lambda 架构和 Kappa 架构这两种大规模数据处理架构,它们都各自有着自身的优缺点。我们需要按照实际情况来权衡利弊,看看在业务中到底需要使用到哪种架构。

如果你所面对的业务逻辑是设计一种稳健的机器学习模型来预测即将发生的事情,那么你应该优先考虑使用 Lambda 架构,因为它拥有批处理层和速度层来确保更少的错误。

如果你所面对的业务逻辑是希望实时性比较高,而且客户端又是根据运行时发生的实时事件来做出回应的,那么你就应该优先考虑使用 Kappa 架构。

Guess you like

Origin www.cnblogs.com/xiaodf/p/11571560.html