我正在与NodeJS,Kafka和Elasticsearch栈进行一个项目。我们有一个账户微服务,需要确保账户余额和交易的数据一致性(余额只能对某些客户为负)。
考虑到我们不需要事务的结果是实时的,每个操作都可以异步处理,然后将结果显示给客户,有一些模型(如事件采购,CQRS)可以在没有ACID数据库的情况下提供事务的数据一致性?
如果这个模型很难做到ACID数据库已经在做的事情(而且做得很好),我们将实现一个SQL数据库(PostgreSQL)来适应这种情况。
发布于 2018-05-04 22:21:11
这不是创建Elasticsearch的目的。尽管您可以在一定程度上使用事务和锁定,但它将保持“最终一致”的数据库
您可以查看以下链接,了解elasticsearch中提供的内容:
https://www.elastic.co/blog/versioning
https://www.elastic.co/guide/en/elasticsearch/guide/current/concurrency-solutions.html
https://www.elastic.co/blog/found-elasticsearch-as-nosql
https://discuss.elastic.co/t/transactional-acid-features-in-es/5357/2
versioning的用例
假设我们需要更新来自不同工作进程的资源。常见的方法是:
在竞争条件的情况下,只有第一个服务将执行请求而不会出现错误。其他竞争者将不得不尝试,直到他们成功。Elasticsearch保证了这类事务的一致性。
示例:
# creating the resource, take a look on _version field
# POST test/resources/42
{
"_index": "test",
"_type": "resources",
"_id": "42",
"_version": 1,
"result": "created",
"_shards": {
"total": 1,
"successful": 1,
"failed": 0
},
"created": true
}
# reading the resource
# GET test/resources/1
{
"_index": "test",
"_type": "resources",
"_id": "1",
"_version": 1,
"found": true,
"_source": {
"value": 1
}
}
# service number 1 trying to update the resource using version in url
# POST test/resources/1?version=1
# {...}
# response has new version
{
"_index": "test",
"_type": "resources",
"_id": "1",
"_version": 2,
"result": "updated",
"_shards": {
"total": 1,
"successful": 1,
"failed": 0
},
"created": false
}
# service number 1 trying to update the resource -- fails
# POST test/resources/1?version=1
# {...}
{
"error": {
"root_cause": [
{
"type": "version_conflict_engine_exception",
"reason": "[resources][1]: version conflict, current version [2] is different than the one provided [1]",
"index_uuid": "nQcwn90wQ9WauH9ySC7qEw",
"shard": "3",
"index": "test"
}
],
"type": "version_conflict_engine_exception",
"reason": "[resources][1]: version conflict, current version [2] is different than the one provided [1]",
"index_uuid": "nQcwn90wQ9WauH9ySC7qEw",
"shard": "3",
"index": "test"
},
"status": 409
}
发布于 2018-05-04 23:30:27
是的,你可以做transactional processing in Apache Kafka (vid),你也可以使用kafka-connect-elasticseach连接器(more info)将数据幂等地登陆到Elastic。
https://stackoverflow.com/questions/50176818
复制相似问题