DMN 或数据库表中的业务规则?
我正在学习 Camunda 工作流引擎。我知道,对于一些长期运行的流程,流程建模带来了许多战术和战略上的好处,例如表达性、容错性和可观察性,当然还有额外的开销。
我正在阅读的这本书还提倡使用DMN(决策表)将业务规则捆绑到流程模型中。动机是集中维护并将配置与代码分离。我对这个建议持保留态度,因为决策表使用起来有点笨拙。没有强类型和强大的IDE功能。我习惯于将业务参数存储在数据库表中并由应用程序使用的实现。该实现还提供管理 GUI 来在运行时维护这些参数。
出于什么原因,我应该选择 DMN 而不是更可靠的基于数据库的解决方案?
I'm learning Camunda the workflow engine. I understand that for some long-running processes, process modeling brings many tactical and strategic benefits such as expressiveness, fail-tolerance and observability with additional overhead ofcourse.
The book I'm reading also advocates the use of DMN (decision tables) to bundle business rules inside the process model. The motive is to centralize maintenance and decouple configuration from the code. I'm taking this advice with grain of salt, as decision tables smells somewhat clunky to work with. There is no strong typing and powerful IDE features. I'm used to implementations where business parameters are stored in database table and consumed by the application. The implementation also provides admin GUI to maintain these parameters at runtime.
For what reason I should favor DMN over more solid database based solution?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您将业务逻辑移至 BPMN,以将其从代码中分离出来,使其在图形模型中透明,可供所有利益相关者访问,支持业务与 IT 协调,使业务能够拥有自己的业务流程/逻辑,支持多版本制定运行时等等...
同样的推理也适用于业务规则,业务规则太复杂,无法在 BPMN 图中建模为图形。 DMN 标准也针对商务人士,并且所使用的表达语言有意保持比 Excel 公式更简单。它是“足够友好的表达语言”(FEEL)。所以你知道这是怎么回事了。
数据库表
这些只是几点。因此,对于业务规则,绝对是 DMN 而不是数据库表。
You are moving the business logic to BPMN to get it out of the code, make it transparent in graphical model, accessible to all stakeholders, support business-IT alignment, empower business to own they business process/logic, support multi-version enactment at runtime, and more...
The same reasoning applies to business rules, which are too complex to be modeled out as graphs in BPMN diagrams. The DMN standard is also aimed at business people and the expression language used is intentionally kept simpler than an Excel formula. It is the "Friendly Enough Expression Language" (FEEL). So you see where this is going.
Database tables
These are just a few points. So, for business rules, definitely DMN over DB tables.
DMN 是一种图形表示法。
而数据库表就是数据的物理存储。
这些是不同的级别,并且没有理由不能同时拥有两者:使用 DMN 查看器/编辑器,但将其数据存储在数据库表中,而不是文件中。
实际上,与 Camunda 您已经内置了此功能。
有了数据库,就有多种使用场景。例如,您可以使用另一个应用程序读取 Camunda 规则并验证它们。或者将 Camunda 规则表与另一个规则表同步。
缺点是 Camunda 并不将其数据库架构视为公共 API,它可以在次要版本之间进行更改。但DMN部分相当稳定,所以风险并不高。
至于强类型,我认为它的用处被高估了。
在很多情况下,强输入验证是不可能的或需要太多的努力,而这些成本永远不会得到回报。
如果一个工具有一些验证方法,那就好,使用它们。但如果没有,请不要将其视为障碍。
您绝对应该防止出现高概率错误。
但除了验证之外,还有其他方法可以实现这一点。例如,指定类型的变量前缀 (
isAvailable
) 可以防止错误的类型间比较。无论如何,所有错误都会在运行时被捕获。
将其与编程语言进行比较。许多现代的不提供强类型,但它们工作得很好。
DMN is a notation with graphical representation.
And a database table is the physical storage of data.
These are different levels, and there is no reason why you can't have both: use DMN viewer/editor, but store its data in a database table, not in a file.
Actually, with Camunda you already have this capability built-in.
With database, there are multiple scenarios how to use it. For example, you can read Camunda rules with another app and validate them. Or sync Camunda rules table with another one.
The downside is that Camunda doesn't consider its database schema as a public API, it can be changed between minor versions. But DMN part is pretty stable, so it's not a high risk.
As for strong typing, I think its usefulness is overestimated.
There are too many circumstances when strong input validation is impossible or requires too much effort, and these costs are never paid off.
If a tool has some validation methods, good, use them. But if it doesn't, don't consider it as an obstacle.
You should definitely prevent errors that have a high probability.
But there are other methods how to achieve that, besides validation. For example, variable prefixes specifying type (
isAvailable
) could prevent erroneous inter-type comparisons.All errors will be caught in runtime anyway.
Compare this with programming languages. Numerous modern ones don't provide strong typing, and they work pretty well.