<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Microservices &#8211; Zhijun Chen</title>
	<atom:link href="https://zhijunchen.com/tag/microservices/feed/" rel="self" type="application/rss+xml" />
	<link>https://zhijunchen.com</link>
	<description></description>
	<lastBuildDate>Fri, 29 Apr 2022 22:13:57 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.5.4</generator>

<image>
	<url>https://zhijunchen.com/wp-content/uploads/2021/03/cropped-my-site-icon-1-32x32.png</url>
	<title>Microservices &#8211; Zhijun Chen</title>
	<link>https://zhijunchen.com</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>How We Are Migrating Monolith To Microservices On AWS</title>
		<link>https://zhijunchen.com/how-we-are-migrating-monolith-to-microservices-on-aws/</link>
		
		<dc:creator><![CDATA[Zhijun Chen]]></dc:creator>
		<pubDate>Fri, 29 Apr 2022 22:13:57 +0000</pubDate>
				<category><![CDATA[Architecture]]></category>
		<category><![CDATA[Kafka]]></category>
		<category><![CDATA[Microservices]]></category>
		<guid isPermaLink="false">https://zhijunchen.com/?p=174</guid>

					<description><![CDATA[Our legacy application is a monolith hosting on multiple EC2 machines on AWS. We are currently under the process of migrating it to microservices architecture mainly due to the following reasons: It is not modular and things are tightly coupled so teams are stepping on each other&#8217;s toes while developing on it The technology is [&#8230;]]]></description>
										<content:encoded><![CDATA[
<p>Our legacy application is a monolith hosting on multiple EC2 machines on AWS. We are currently under the process of migrating it to microservices architecture mainly due to the following reasons:</p>



<ul><li>It is not modular and things are tightly coupled so teams are stepping on each other&#8217;s toes while developing on it</li><li>The technology is outdated and we don&#8217;t have the expertise on continuous maintenance and development</li><li>The application is poorly tested in general therefore we don&#8217;t feel safe to change the system. One simple change could result in bugs in other places we are not aware of.</li><li>Various performance issues</li></ul>



<p>The migration comes with the following challenges:</p>



<ul><li>We still need to keep the monolith running and serving our customers.</li><li>We can&#8217;t afford a complete rewrite of the monolith as that would take ages.</li></ul>



<p>Our team decided to follow <a rel="noreferrer noopener" href="https://martinfowler.com/bliki/StranglerFigApplication.html" target="_blank">Strangler Fig Pattern</a> and gradually tear the monolith apart.</p>



<p>Here is how the entire migration process looks like:</p>



<figure class="wp-block-image size-full"><img fetchpriority="high" decoding="async" width="686" height="630" src="//i3.wp.com/zhijunchen.com/wp-content/uploads/2022/04/migration-3.png" alt="" class="wp-image-181" srcset="https://zhijunchen.com/wp-content/uploads/2022/04/migration-3.png 686w, https://zhijunchen.com/wp-content/uploads/2022/04/migration-3-300x276.png 300w" sizes="(max-width: 686px) 100vw, 686px" /><figcaption>Monolith Migration</figcaption></figure>



<p>In order for this to work we need to identify our bounded contexts/domains following <a rel="noreferrer noopener" href="https://martinfowler.com/bliki/DomainDrivenDesign.html" target="_blank">domain-driven design</a>. One useful way for this process would be <a rel="noreferrer noopener" href="https://techbeacon.com/app-dev-testing/introduction-event-storming-easy-way-achieve-domain-driven-design" target="_blank">Event Storming</a>. The In this case Domain A would be represented in the diagram as Frontend Application A, Backend Microservice A and Database A, these will run inside ECS or EKS behind a Service Mesh.</p>



<p>We take what we need from the monolith by streaming change log from RDS read replica via <a rel="noreferrer noopener" href="https://docs.aws.amazon.com/dms/latest/userguide/Welcome.html" target="_blank">AWS Data Migration Service</a> to <a rel="noreferrer noopener" href="https://aws.amazon.com/msk/" target="_blank">AWS MSK</a> topic, which will give us <a href="https://kafka.apache.org/" target="_blank" rel="noreferrer noopener">Kafka</a> events which look like the following:</p>



<pre class="wp-block-code"><code>{
  "topic": "&lt;topic_name>",
  "partition": 3,
  "offset": 53870799,
  "tstype": "create",
  "ts": 1651268333902,
  "broker": 2,
  "key": "&lt;partition_key>",
  "payload": "&lt;the_actual_payload>",
  "_datetime": "2022-04-29T21:38:53Z",
  "_payload": {
    "data": {
      "id": 1,
      "createdOn": "2021-01-23T20:38:16Z",
      "modifiedOn": "2022-04-29T15:45:04Z",
      "version": 0,
      "firstName": "Foo 2",
      "lastName": "Bar 2"
    },
    "before": {
      "id": "1",
      "firstName": "Foo",
      "lastName": "Bar"
    },
    "metadata": {
      "timestamp": "2022-04-29T21:38:53.752816Z",
      "record-type": "data",
      "operation": "update",
      "partition-key-type": "primary-key",
      "schema-name": "&lt;schema_name>",
      "table-name": "&lt;table_name>",
      "transaction-id": 569130413019234
    }
  }
}</code></pre>



<p>Since we are already on AWS we try to its services available. If you are not on AWS, then AWS Data Migration Service could be replaced with <a href="https://debezium.io/" target="_blank" rel="noreferrer noopener">Debezium</a>.</p>



<p>Then we create a CDC service transforming raw change event into domain event, this is acting as our ACL (Anti Corruption Layer).</p>



<p>From now on inside each microservice we have Kafka consumers to pick up the events and persist it into individual databases.</p>



<p>On Application Load Balance layer we will forward requests to either old monolith or new microservice frontend based on routing rules. If we are happy with the new microservice then we will deprecate things inside the monolith and make it smaller. Repeating the process would eventually allow us to split the monolith.</p>



<p>During the process monolith application would likely need the data from the new microservices, we can either follow the same approach to feed the data back. How kafka consumer interacts with monolith would depend on individual cases.</p>



<p>There will a lot of issues to resolve along the way but hopefully this will get us where we want to be in future.</p>



<p>Here are some important things to bear in mind during the migration process:</p>



<ul><li>Think about whether what you need is just modular monolith instead of microservices architecture.</li><li>Keep minimal changes to the monolith.</li><li>Start with the most independent domain.</li><li>Follow Kafka best practices, e.g. make sure Kafka consumers are idempotent.</li><li>Have faith that all these work will eventually be paid off as it will be a long journey.</li></ul>



<p></p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
