【问题标题】:External entity links and API design外部实体链接和API设计
【发布时间】:2023-02-16 17:41:41
【问题描述】:

我正在设计一个系统,设计的核心与我们的其他系统及其限界上下文完全分离。

我的新系统的核心实体是 ENTITY_A。

当技术团队与系统集成时,ENTITY_A 需要与其他系统中的实体 ENTITYB 或 ENTITYC 等相关联。这将在平台的可扩展层中完成。

我想要一些建议的两个挑战:

  • 我们如何建模软外键(即存储 id 和实体名称)
  • 我们如何在我们的 API 上启用搜索以允许查询 ENTITY_A 基于 ENTITY_B 或 ENTITY_C 的键?

想法?

【问题讨论】:

    标签: architecture


    【解决方案1】:

    If I understand correctly, you are asking if there is a better approach than just store ENTITY_B.Id in ENTITY_A.BId. While this approach is fine, you should consider ability to query ENTITY_B data from system B and how strong system A relies on that data. In particular how system A should behave if B is not reachable or ENTITY_B is deleted.

    I would recommend always begin with having some internal representation of external entities. This representation should hold data (other than key) that is important for system A but is unlikely to change in B or can be outdated. In my experience such kind of data always exists and dealing with outdated data in small isolated part of a system is usually easier than dealing with inconsistency in every part of a system. Internal representation also helps with updating data. It can hold last update time or synchronization status.

    For example let ENTITY_A_B be an entity representing ENTITY_B in system A. We want UI in A able to display ENTITY_B.Name without querying B (for both performance and accessibility). So we can model entities in A like this:

    ENTITY_A_B {
    BId,
    Name
    }
    ENTITY_A.BId strongly references ENTITY_A_B.BId
    ENTITY_A_B.BId softly references ENTITY_B.Id
    ENTITY_A_B.Name keeps value of ENTITY_B.Name
    
      猜你喜欢
      • 1970-01-01
      • 2017-01-28
      • 2013-07-05
      • 1970-01-01
      • 1970-01-01
      • 2016-09-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多