# 数据异构

## 什么是数据异构

数据异构体现在很多个层次上：

1. 数据存储地点的异构：数据存储在多个物理位置上，比如mysql集群，在北京，上海都有节点。
2. 数据格式的异构：数据的存储管理机制不同，可以是关系型数据库系统，如：Mysql、SQL Server、DB2等，也可以是非关系型数据库，比如redis，MongoDB等，也可以是文件行二维数据，如：txt、CSV、XLS等。
3. 数据的逻辑模型异构：数据分别在不同的业务逻辑中存储和维护，从而相同意义的数据存在表现的异构；如：独立的销售系统和独立的采购系统中存在产品的字段不相同等。
4. 操作系统的异构；数据的存储来源于不同的操作系统，如：Unix、Windows、Linux、OS/400等。
5. 计算机体系结构的异构；数据的物理存储来源于不同体系结构的计算机中，如：大型机、小型机、工作站、PC或嵌入式系统中。

## 数据格式异构实现的方式

目前业界比较流行的数据格式异构方式有三种：

* 双写：在写入数据的时候，同时将数据写入mysql和缓存；
* MQ：写入mysql成功后，发一个mq消息，缓存读取mq消息并将消息写入缓存；
* Binlog：写入mysql后，缓存系统x消费binlog，将变动写入缓存。

三种实现方式的优缺点对比：

|       | 双写    | MQ    | Binlog |
| ----- | ----- | ----- | ------ |
| 数据一致性 | 存在不一致 | 存在不一致 | 存在不一致  |
| 数据延迟  | 低     | 中     | 高      |
| 系统耦合度 | 高     | 中     | 低      |
| 系统复杂度 | 低     | 中     | 高      |


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://jun-wang.gitbook.io/learnjava/ji-shu-xue-xi/jia-gou-xue-xi/shu-ju-yi-gou.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
