当前位置:网站首页>Treatment of idempotency
Treatment of idempotency
2022-04-23 15:39:00 【dengk2013】
What is idempotency ? Sending an interface call and sending the same interface message multiple times can get the result that is consistent with the expectation
If there is an interface that provides salary increase , If you call add... Once 500 Yuan , If you don't control the problem of idempotency ,
Keep calling the interface , Then the employee's salary has been increasing
// Inquire about 1 Employee No
Employee employee = employeeService.selectById(1);
// Update salary
employee.setSalary(employee.getSalary() + incrSalary);
// Execute UPDATE statement
employeeService.update(employee)
What's the problem? ? Right , Every time you resend a request 1 No. salary will +500, Idempotency is destroyed
How to solve ? The traditional method is to add pre judgment to the code , That is, by adding a flag and salary increase time
if(! The employee has been paid && Raise time +6 Months < Current system time )
{
Carry out salary adjustment
}
What's wrong with ? There are too many areas for pre judgment , If you don't pay attention, you'll miss This technical problem should not be a factor that interferes with programmers writing business code
We need a non intrusive idempotent solution Building idempotent tables is our general solution Let the brothers concentrate on writing CRUD That's it
advantage : The background service has no code intrusion , No need to modify business logic
shortcoming : The foreground application should be transformed for idempotence Increased architecture complexity , Additional deployment is required Nginx、Redis
版权声明
本文为[dengk2013]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231537380036.html
边栏推荐
猜你喜欢
Multitimer V2 reconstruction version | an infinitely scalable software timer
Basic concepts of website construction and management
Special analysis of China's digital technology in 2022
基于 TiDB 的 Apache APISIX 高可用配置中心的最佳实践
时序模型:门控循环单元网络(GRU)
单体架构系统重新架构
Independent operation smart farm Innovation Forum
T2 icloud calendar cannot be synchronized
Mysql database explanation (8)
2022年中国数字科技专题分析
随机推荐
mysql乐观锁解决并发冲突
Deeply learn the skills of parameter adjustment
Independent operation smart farm Innovation Forum
CVPR 2022 优质论文分享
Explanation of redis database (I)
单体架构系统重新架构
深度学习调参的技巧
php函数
utils.DeprecatedIn35 因升级可能取消,该如何办
大型互联网为什么禁止ip直连
Upgrade MySQL 5.1 to 5.68
What if the package cannot be found
Upgrade MySQL 5.1 to 5.67
小程序知识点积累
PHP operators
Modèle de Cluster MySQL et scénario d'application
为啥禁用外键约束
移动金融(自用)
APISIX jwt-auth 插件存在错误响应中泄露信息的风险公告(CVE-2022-29266)
Basic concepts of website construction and management