避免在数据库设计和系统图中陷入反模式
Avoiding fan traps in database design and system diagrams

原始链接: https://www.ilograph.com/blog/posts/avoid-fan-traps-in-system-diagrams/

## 风扇陷阱:图表中的信息丢失 “风扇陷阱”出现在数据建模和系统图表中,当多个一对多连接在“一对”端连接时,或者关系坍缩到单个中间资源上时,关系会变得模糊。这会导致特定连接信息丢失——例如,错误地将教授直接映射到学院,而不是通过他们的部门。 在系统架构中,风扇陷阱通常出现在事件驱动系统(围绕事件代理)和网络图中(围绕防火墙),暗示可能实际不存在的连接。 有三种方法可以解决这个问题: 1. **更具体:** 在中间资源(如事件代理中的“主题”或防火墙规则)*内部*添加细节以明确连接。这可能很复杂,并非总是可行。 2. **直通箭头:** 在不添加细节的情况下,在中间资源*通过*保持连接,提供一个更简单的解决方案。 3. **什么都不做:** 如果图表的目的是显示*潜在*的而不是*实际*的通信,那么这种模糊可能是可以接受的,特别是对于网络安全工程师等受众。 最终,最佳解决方案取决于图表的目标和受众的需求。

这个Hacker News讨论强调了一个常见的数据库设计问题,称为“风扇陷阱”——多对多关系变得过于复杂和难以理解的情况。链接文章(ilograph.com)详细介绍了如何在数据库设计和系统图中避免这些陷阱。 核心问题是在跟踪事件和关系时保持上下文。一位来自投资模拟领域的评论员指出,时间序列数据面临类似的挑战,他们通过预计算数据并用特定的历史“状态”(如市场状况)进行标记来解决这个问题。这使得能够精确回答某些事件发生的原因。 一个关键问题是,为了提高跟踪的精确度而添加过多细节,最终是否会由于增加复杂性而阻碍对整个系统的理解。另一位评论员简单地肯定了理解关系建模的重要性,这是几十年数据建模课程中教授的概念。
相关文章

原文

A fan trap in data modeling occurs when multiple 1:N relations are joined on the “1” side, resulting in information loss. To the uninitiated, this is easiest understood by example: imagine a university with many colleges, each with many departments, which in turn have many professors. If modeled incorrectly, where the professors are given 1:N relations with colleges instead of departments, the result is a fan trap:

In data modeling, a fan-trap occurs when relations between entities is ambiguous.

These relations aren’t wrong per se, but the mapping of professors to departments is lost. The resulting data modeling diagram looks like two hand fans joined at the narrow end, hence the name.

"Fan trap" gets its name from its resemblance to a hand fan.

A similar problem can occur in system diagramming. When diagramming relations between resources in a system, information can similarly be lost when relations flow through an intermediary resource. In this article, we’ll look at a couple of examples of this problem and three potential fixes.

Fan Traps in System Architecture Diagramming

Fan traps are common problems when diagramming event-driven architectures. The defining characteristic of such architectures is that resources communicate via events. Events are typically routed through an event broker, which temporarily stores them until they are ready for consumption. This architecture has the added benefit of decoupling the resources, since they no longer communicate directly.

When diagrammed, a (highly simplified) event-driven system might look like so:

In system architecture diagramming, a fan-trap occurs when relations collapse onto a single resource.

The similarity to fan traps in data modeling should be evident at a glance. The relationships between the message-producing resources (on the left) and message-consuming resources (on the right) are lost because they collapse at the center of the “fan” (the event broker). The diagram implies each producer communicates with all of the consumers, even though this may not be the case:

When a fan trap is present, relations between edge nodes can be ambiguous.

The same problem can emerge when diagramming communication paths in a network:

The firewalls in this diagram are causing a fan trap.

In the (again highly simplified) networking diagram above, node-to-node communications across the network fan out and back in through firewalls, resulting in specific communication paths being lost.

Solution 1: More specificity

One potential solution is to add smaller, discrete resources within the intermediate resource that the edge resources can connect through. In the event-driven architecture example above, adding “topics” allows us to differentiate the communications going through the event broker:

Adding topics to the event broker fixes the fan trap.

With the addition of topics, the individual communication paths can now be discerned:

The individual relations are now visible.

In the networking example, adding firewall rules to the firewall accomplishes the same:

Adding fine-grained firewall rules to the diagram can resolve the fan trap.

This solution is not foolproof, however. If, for example, the firewall rules are too generic, then the connections will remain ambiguous:

If the firewall rules are too broad, the fan trap remains.

Furthermore, it is sometimes impossible or impractical to disambiguate connections via intermediate resources. Adding “The Internet” as an intermediate resource between all communications best demonstrates this:

Breaking down some intermediate resources to resolve ambiguities is impossible.

Solution 2: Pass-through arrows

Adding additional intermediate resources to disambiguate communications is extra work that may not resolve the issue, even when feasible. A second, possibly better, solution is to add pass-through arrows to the intermediate resources:

Pass-through arrows can be used to resolve ambiguoities caused by fan traps.

Pass-through arrows retain connections between edge nodes through intermediate resources without the need for added resources:

Individual relations are visible again.

Pass-through arrows require less work and yield simpler diagrams than adding detailed intermediate resources. The trade-off, naturally, is less detail.

Solution 3: Do nothing

Before disambiguating relations with additional resources or pass-through arrows, consider the diagram’s goal and target audience. Depending on the viewer’s perspective, fanned-out relations may not even be a problem.

If the goal is to show the paths of actual communications between resources, then disambiguate the relations. Software engineers, architects, and SREs are likely interested in this information.

Conversely, if the goal is to show potential communication paths between resources, consider keeping the diagram as-is (i.e., with fanned relations). Network and security engineers, especially, would want to see this perspective on the system.

Questions or comments? Please reach out to me on LinkedIn or by email at [email protected].

Share this article on LinkedIn

Share this article on Facebook

联系我们 contact @ memedata.com