Congratulations! You now have a serverless application stack running in both Oregon and Ireland. The stacks you deployed with Chalice each contain the following core components:
You then used the AWS Command Line Interface to deploy a DynamoDB Global Table called global-serverless and fill it with several items. These items represent bookmark records that can be set to record and retrieve the progress a customer has made when watching video content. There are also items representing a catalog of video content available.
Our table has a two-part primary key consisting of a Partition Key and a Sort Key, named PK and SK. Each bookmark record will have the viewer’s UserID as the PK value, and a ContentID value in the SK to denote the video they are watching. A third attribute, called Bookmark, will record the progress. The application will make periodic updates to this Bookmark attribute as the show is watched. If the user stops and then returns again later, a Get-Item call can locate the bookmark, read the Bookmark value, and queue up the video player to the right spot for the customer to continue watching.
When the application stack in Oregon makes calls to DynamoDB, it connects to the DynamoDB table in the same region. We can call this local table a regional replica since it participates in Global Tables replication. Writes to any regional replica will be detected by the DynamoDB service and the new item image will be shipped and applied to all other regional replicas. The goal of Global Tables is to bring all replicas to an identical state as quickly as possible. Callers such as our Lambda function in Oregon do not need to be aware of other regions and do not connect to any global endpoint since there isn’t one.
Write operations to a replica table are confirmed successful to the caller with the same performance as a non-Global Table, typically within 10 milliseconds.
The distance between Oregon and Ireland is 4500 miles (7000 km). Information traveling at the speed of light will cross this distance in 24 ms.
The time it takes for DynamoDB to replicate changes to other regions can vary, but is typically 1-2 seconds. The ReplicationLatency statistic in Cloudwatch tracks the time required to replicate items.
Let’s prove that Global Tables replication is working.
+
in the first region and notice that the new bookmark value is displayed.The goal is to check the bookmark in region two before the replication completes. Since replication can occur in about one second, you will have to be quick to detect this. If you do, then click Get-Item again and the synchronized value should now be shown.
Note the app keeps a timer after every update, so you can see how many seconds have elapsed when performing a subsequent read.
There is an edge case with Global Tables that happens when writes to the same item occur at the same time in different regions. If the writes conflict during the 1-2 seconds of in-flight replication, then DynamoDB detects this as a Conflict, and makes a decision on which one of the writes will win the conflict. The timestamps of the updates are compared, and the later write becomes the winner. The earlier write is thrown out as if it never happened.
You can read more about DynamoDB Global Tables in the final chapter of this workshop or in the Global Tables Documentation