官术网_书友最值得收藏!

How to do it...

Migrating data from a monolith database to a new store fronted by a new service, without any impact on availability or consistency, is a difficult but common task when making the transition to microservices. Using our fictional photo-messaging application, we can imagine a scenario where we want to create a new microservice responsible for handling media uploads. In this scenario, we'd follow a common dual-writing pattern:

  1. Before writing a new service to handle media uploads, we'll assume that the monolith architecture looks something like the following diagram, where HTTP requests are being handled by the monolith, which presumably reads the multipart/form-encoded content body as a binary object and stores the file in a distributed file store (Amazon's S3 service, for example). Metadata about the file is then written to a database table, called attachments, as shown in the following diagram:

  1. After writing a new service, you now have two write paths. In the write path in the monolith, make a call to your service so that you're replicating the data in the monolith database as well as the database fronted by your new service. You're now duplicating new data and can write a script to backfill older data. Your architecture now looks something like this:
  1. Find all read paths in your Client and Monolith code, and update them to use your new service. All reads will now be going to your service, which will be able to give consistent results.
  2. Find all write paths in your Client and Monolith code, and update them to use your new service. All reads and writes are now going to your service, and you can safely delete old data and code paths. Your final architecture should look something like the following (we'll discuss edge proxies in later chapters):

Using this approach, you'll be able to safely migrate data from a monolith database to a new store created for a new microservice without the need for downtime. It's important not to skip this step; otherwise, you won't truly realize the benefits of microservice architectures (although, arguably, you'll experience all the downsides!). 

主站蜘蛛池模板: 龙山县| 郁南县| 麻江县| 正阳县| 荔浦县| 怀化市| 建始县| 克什克腾旗| 双城市| 承德县| 蚌埠市| 东丰县| 青海省| 红河县| 开封县| 道真| 油尖旺区| 临澧县| 岳西县| 遂宁市| 准格尔旗| 贵港市| 陈巴尔虎旗| 康乐县| 金坛市| 阿拉善盟| 临武县| 吉木乃县| 宁化县| 珠海市| 正阳县| 青州市| 汕头市| 兴宁市| 本溪| 潜山县| 开封县| 鲜城| 潞西市| 德江县| 稷山县|