必读rss订阅源_开始时您需要了解的事件源必读

必读rss订阅源

by Noël Widmer

由NoëlWidmer

开始时您需要了解的事件源必读 (Event sourcing essentials you need to know when starting out)

Event Sourcing is a thought challenge when starting out. In this story, I will describe my experiences from the perspective of an engineer.

开始时,事件来源是一个思想挑战。 在这个故事中,我将从工程师的角度描述我的经验。

My goal is to help you decide if you want to invest the resources to get started with Event Sourcing.

我的目标是帮助您确定是否要投入资源来开始使用事件采购。

关于作者 (About The Author)

Hi ? I’m Noël. I live near Zurich (Switzerland) and am proudly working on Switzerland’s largest E-Commerce platform. My team and I have applied Event Sourcing throughout the last 12 months, and we learned a lot.

嗨 我是Noël。 我住在瑞士苏黎世附近,正在为瑞士最大的电子商务平台而自豪。 在过去的12个月中,我和我的团队一直在应用Event Sourcing,并且学到了很多东西。

I want to share four essentials with you that I wish we knew one year ago.

我希望与您分享四件事,我希望我们在一年前就知道。

小型事件采购简介 (A Tiny Introduction To Event Sourcing)

This article is not about introducing you to the concepts of Event Sourcing. I still feel like I should take one step back though — to paint a clearer picture.

本文并不是要向您介绍事件源的概念。 我仍然觉得我应该退后一步 -画出清晰的画面。

In state-oriented applications, you store the result of some computation in your data store. You might also keep a log where you archive old states for auditing or debugging purposes. But by storing state you lose the information about the transition from one state to the other. If a user’s username has disappeared, you’ll be wondering how that could have happened.

在面向状态的应用程序中,您将一些计算结果存储在数据存储中。 您可能还会保留一个日志,在该日志中您将旧状态存档以进行审核或调试。 但是,通过存储状态,您将丢失有关从一种状态到另一种状态的转换的信息。 如果用户的用户名消失了,您会想知道这是怎么回事。

Sourcing events preserves that information. This is achieved by storing state transitions rather than the resulting state.

采购事件将保留该信息。 这是通过存储状态转换而不是结果状态来实现的。

The current state can be restored by applying all events to an empty canvas. That means we can still access the current state but need to invest computational resources to do so.

通过将所有事件应用于空画布可以恢复当前状态。 这意味着我们仍然可以访问当前状态,但是需要投入计算资源来访问当前状态。

There are many articles on the web that go into more detail. Martin Fowler wrote one about it. And Greg Young talks a lot about Event Sourcing. Greg is so obsessed with event sourcing that he implemented a data store which is specifically designed for event sourcing. My team is using Greg’s event store — it’s great!

网络上有许多文章都进行了更详细的介绍。 马丁·福勒( Martin Fowler)就此写了一篇 。 Greg Young 谈到了很多事件采购 。 Greg对事件源非常着迷,以至于他实现了专门为事件源设计的数据存储 。 我的团队正在使用Greg的活动存储-太好了!

1)事件来源不是银弹 (1) Event Sourcing Is Not A Silver Bullet)

Once you fall for the bitter sweet taste of Event Sourcing it becomes compelling to apply the concept to all your problems.

一旦您沉迷于Event Sourcing的苦涩甜味,就必须将这一概念应用于所有问题。

This will provide you with loads of data to analyze and you will have a powerful foundation to detect interesting correlations in it. You’ll be able to detect inefficient processes and make them more efficient.

这将为您提供大量数据进行分析,并且您将拥有强大的基础来检测其中有趣的关联。 您将能够检测到效率低下的流程,并使它们更有效率。

And every engineer’s (my) favorite:

和每个工程师(我)最喜欢的:

Tracking down a bug becomes much easier when you can “time travel” to the exact moment when the bug happened. In the end you will save time and money.

当您可以“时间旅行”到错误发生的确切时间时,查找错误变得容易得多。 最后,您将节省时间和金钱。

Well — not quite. ☝️

好吧-不完全是。 ☝️

Sourcing your events sure allows you to do the analysis. But you still need to do it. This will cost time. Luckily, “time travel” comes for free. Enhanced debugging is thus guaranteed from day one.

确定事件的来源可确保您进行分析。 但是您仍然需要这样做。 这将花费时间。 幸运的是,“时间旅行”是免费提供的。 从一开始就保证了增强的调试。

Seth Godin wrote a great blog post on the subject. It’s a 2 minute read, so check it out.

塞思·戈丁(Seth Godin)就该主题写了一篇很棒的博客文章 。 这是2分钟的阅读时间,请检查一下。

Now you know about the price you’ll pay if you use your events for analytical purposes which is the main business benefit of Event Sourcing after all.

现在,您知道了将事件用于分析目的所要支付的价格,这毕竟是事件采购的主要业务优势。

There is another cost though. Event Sourcing will increase the complexity of your application. Instead of dealing with your application’s current state you’ll have to deal with everything that has ever happened since it went live. Events that are no longer used will remain in your data store and you’ll have to support them for a long time.

不过,还有另一笔费用。 事件源将增加应用程序的复杂性。 除了处理应用程序的当前状态外,您还必须处理应用程序上线以来发生的所有事情。 不再使用的事件将保留在您的数据存储中,并且您将需要长时间的支持。

It’s great if you deploy a feature and keep iterating on it. Just be aware that there are now multiple versions of that feature’s events in your data store and you’ll have to support all of them. Even if you no longer create new instances of those events.

如果您部署一项功能并不断对其进行迭代,那就太好了。 请注意,您的数据存储中现在有该功能事件的多个版本,您将必须支持所有版本。 即使您不再创建这些事件的新实例。

Event Sourcing imposes additional time complexities that you will have to get used to. Apply it where you see a non-zero chance that the collected data becomes relevant. Where I’d define “relevant” as:

事件源强加了您必须习惯的其他时间复杂性。 将其应用到收集到的数据变得不相关的可能性非零的位置。 我将“相关”定义为:

  • the data could give you more insight into your domain

    数据可以让您更深入地了解自己的域名
  • the data could help your business to improve their processes on their own

    数据可以帮助您的企业自行改善流程
  • the data could help you find bugs faster

    数据可以帮助您更快地发现错误

Note that I added the word “could” in each of the last three bullet points. It’s likely you won’t know the exact benefit of Event Sourcing in advance. Make your best guess.

请注意,我在最后三个要点中都添加了“可能”一词。 您可能事先不知道事件采购的确切好处。 做出最好的猜测。

2)认识事件源的功能性质 (2) Recognize The Functional Nature Of Event Sourcing)

The authors of the famous Patterns, Principles, and Practices of Domain-Driven Design recommend object-oriented programming languages like C# or Java.

领域驱动设计的著名模式,原理和实践的作者推荐了诸如C#或Java之类的面向对象的编程语言。

I assume that the implicit reasoning behind that recommendation is the number of people using such languages. It’s true. New team members will likely have an easier start into the domain when confronted with familiar languages.

我认为该建议背后的隐含推理是使用这种语言的人数。 这是真的。 新团队成员在面对熟悉的语言时可能会更轻松地进入领域。

But I disagree. So does Greg Young. Event Sourcing is not an object-oriented concept.

但我不同意。 格雷格·扬(Greg Young)也是如此事件源不是一个面向对象的概念。

One might argue that state transitions are objects too. And indeed. You can model everything as objects. Just because you can does not imply that this is the best model to use.

有人可能会说状态转换也是对象。 的确如此。 您可以将所有内容建模为对象。 仅仅因为您可以,并不意味着这是最好的模型。

Consider using a language that supports functional paradigms. Especially tagged unions and pattern matching are extremely valuable. Working with your events will feel natural and you won’t have to fight your language’s type system. If your team has no experience with the functional world it might be best to stick to familiar languages though.

考虑使用支持功能范例的语言。 特别是带标签的联合模式匹配非常有价值。 处理您的事件将很自然,并且您不必与语言的类型系统作斗争。 如果您的团队没有使用功能世界的经验,那么最好还是使用熟悉的语言。

Even more important to understand is that choosing a relational data store will be a painful experience. You’re not dealing with relational data when sourcing your events. Each event has its own schema which can change over time. Using a relational data store will hurt.

更重要的是要了解, 选择关系数据存储将是一件痛苦的经历 。 采购事件时,您无需处理关系数据。 每个事件都有其自己的架构,该架构可以随时间变化。 使用关系数据存储会很痛苦。

SQL is the master of nothing but it sucks at nothing. - Greg Young

SQL是一无是处的大师,但它无济于事。 -格雷格·杨(Greg Young)

3)期待陡峭的学习曲线 (3) Expect A Steep Learning Curve)

As with all new things there will be learning involved. Don’t try to sidestep it. That won’t work.

与所有新事物一样,将涉及学习。 不要试图回避它。 那行不通。

A great way to learn is to prototype. Try this:

学习的好方法是原型。 试试这个:

  • build at least one prototype of your first event sourced application

    构建第一个事件源应用程序的至少一个原型
  • run and observe your prototype for a while

    运行一段时间并观察您的原型
  • implement new features and get used to iterating on what you’ve built

    实施新功能并习惯于迭代所构建的内容

Iterate as often as possible before your go live. Once you are live it won’t be as easy to implement new learnings.

上线之前,请尽可能频繁地进行迭代。 一旦生活了,实施新的学习就不会那么容易了。

Go live once your team feels confident with maintaining the application.

一旦您的团队对维护应用程序充满信心,就可以上线。

Also think about how your team will introduce new team members to Event Sourcing. New joiners are already in an overwhelming position and learning new concepts won’t make it any easier for them.

还考虑一下您的团队如何将新团队成员介绍给Event Sourcing。 新加入者已经处于压倒性的地位,学习新概念对他们而言并不容易。

Figure out a way to introduce them to Event Sourcing in a soft and safe way. This is important to figure out once you start getting new team members. It’s fine to delay it until that happens.

找出一种将它们以软安全的方式介绍给Event Sourcing的方法。 一旦开始招募新的团队成员,这一点很重要。 最好将其延迟到发生这种情况。

4)为政治辩论做准备 (4) Prepare for political debates)

Have you realized that your company wants cheap and quality results today?

您是否意识到您的公司今天想要便宜高质量的结果?

Oh my, who am I talking to — of course you did. ?

哦,天哪,我在跟谁说话-当然可以。 ?

Will they like it when you experiment with a mind-bending concept they might never heard of? And what is your company’s tech stack like? Do you usually use object-oriented programming languages in combination with relational data stores? Will they like it when you switch to a functional tech stack?

当您尝试他们可能从未听说过的创新思维时, 他们会喜欢吗? 贵公司的技术栈如何? 您通常将面向对象的编程语言与关系数据存储结合使用吗? 当您切换到实用的技术堆栈时, 他们会喜欢吗?

Depending on your companies culture you might have to fight your colleagues on multiple fronts. Act as an example. Tell the truth. You know it will be hard, especially in the beginning. Share your concerns. Make sure everyone involved knows the risks and what you’ll do to prevent them.

根据您公司的文化,您可能必须在多个方面与您的同事作斗争。 举个例子。 说实话 您知道这会很困难,尤其是在一开始的时候。 分享您的担忧。 确保涉及的每个人都知道风险以及您将如何采取预防措施。

And don’t leave out how you picture the Event Sourcing paradise. Get the business on board by allowing them to build reports based on your valuable events. They’ll love it.

并且不要遗漏您如何描绘事件采购天堂。 通过允许他们根据您的重要事件来生成报告,从而使公司参与其中。 他们会喜欢的。

Get the concerned engineering people on board by sharing the improved debugging experience. Engineers are stubborn, they might still not like it.

通过共享改进的调试经验来吸引有关的工程人员。 工程师固执己见,他们可能仍然不喜欢它。

I found it useful to practice such debates with my colleagues. Establish a safe environment for training and encourage your team members to take part.

我发现与我的同事进行这样的辩论很有用。 建立一个安全的培训环境,并鼓励您的团队成员参加。

Be ready and know your stuff. You’ll make it! ?

准备好,知道你的东西。 你能做到的! ?

结论 (Conclusion)

Let me summarize.

让我总结一下。

  • More data isn’t always good.

    更多数据并不总是很好。
  • Additional data without the time to analyze it is useless.

    没有时间进行分析的附加数据是没有用的。
  • Analysis without the intention and time to act on the result is useless.

    没有意图和时间对结果采取行动的分析是没有用的。
  • Event Sourcing enhances the ability to debug your application.

    事件源增强了调试应用程序的能力。
  • Event Sourcing is a functional paradigm.

    事件源是功能范式。
  • Expect a steep learning curve.

    期待陡峭的学习曲线。
  • Not everybody will be happy about your plans.

    并非每个人都会对您的计划感到满意。

That’s it. My intention was to prepare your expectations to my experiences. Don’t worry. Be determined and choose the red pill!

而已。 我的意图是使您对我的经历有所期待。 不用担心 确定并选择红色药丸!

矩阵 (The Matrix)

All images in this story are borrowed from the movie The Matrix.

这个故事中的所有图像都是从电影《黑客帝国》中借用的。

I’ve spent 9 years writing object-oriented code and working with relational data stores. About two years ago I started to experiment with functional code and non-relational data stores. The mind shift has been one of the most important lessons in my career to date.

我花了9年的时间编写面向对象的代码并使用关系数据存储。 大约两年前,我开始尝试使用功能代码和非关系数据存储。 迄今为止,思维转变是我职业生涯中最重要的课程之一。

Question your environment. Find the flaws. Exit the Matrix and get to experience a whole new world.

质疑您的环境。 发现缺陷。 退出黑客帝国,体验全新的世界。

Farewell. Until next time. And good luck!

永别了 直到下一次。 还有祝你好运!

I only write about programming and technology. If you follow me, I won’t waste your time. ?

我只写关于编程和技术的文章。 如果您关注我,我不会浪费您的时间。

翻译自: https://www.freecodecamp.org/news/event-sourcing-essentials-you-need-to-know-when-starting-out-13af35d9f932/

必读rss订阅源

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值