Browse Source

3: creating tables.

Frederic G. MARAND 2 years ago
commit
cd44c56f76
11 changed files with 124 additions and 0 deletions
  1. 8 0
      .idea/.gitignore
  2. 9 0
      .idea/dynamodb_demo.iml
  3. 6 0
      .idea/misc.xml
  4. 8 0
      .idea/modules.xml
  5. 6 0
      .idea/vcs.xml
  6. 8 0
      .idea/watcherTasks.xml
  7. BIN
      3-1-eventual-consistency.png
  8. 56 0
      3-creating.md
  9. 11 0
      docker-compose.yml
  10. 9 0
      glossary.md
  11. 3 0
      go.mod

+ 8 - 0
.idea/.gitignore

@@ -0,0 +1,8 @@
+# Default ignored files
+/shelf/
+/workspace.xml
+# Editor-based HTTP Client requests
+/httpRequests/
+# Datasource local storage ignored files
+/dataSources/
+/dataSources.local.xml

+ 9 - 0
.idea/dynamodb_demo.iml

@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<module type="WEB_MODULE" version="4">
+  <component name="Go" enabled="true" />
+  <component name="NewModuleRootManager">
+    <content url="file://$MODULE_DIR$" />
+    <orderEntry type="inheritedJdk" />
+    <orderEntry type="sourceFolder" forTests="false" />
+  </component>
+</module>

+ 6 - 0
.idea/misc.xml

@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="NodePackageJsonFileManager">
+    <packageJsonPaths />
+  </component>
+</project>

+ 8 - 0
.idea/modules.xml

@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="ProjectModuleManager">
+    <modules>
+      <module fileurl="file://$PROJECT_DIR$/.idea/dynamodb_demo.iml" filepath="$PROJECT_DIR$/.idea/dynamodb_demo.iml" />
+    </modules>
+  </component>
+</project>

+ 6 - 0
.idea/vcs.xml

@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="VcsDirectoryMappings">
+    <mapping directory="$PROJECT_DIR$" vcs="Git" />
+  </component>
+</project>

+ 8 - 0
.idea/watcherTasks.xml

@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="ProjectTasksOptions">
+    <enabled-global>
+      <option value="goimports" />
+    </enabled-global>
+  </component>
+</project>

BIN
3-1-eventual-consistency.png


+ 56 - 0
3-creating.md

@@ -0,0 +1,56 @@
+# 3 Creating Elaborate DynamoDB tables
+
+## 3.1 Storage consistency
+
+DDB manages capacity
+
+- 1 WCU (Write Capacity Unit) = 1 write of <=1 kB op per second
+  - write sizes are rounded up to 1kB: 1 w/sec of 500B counts as 1 WCU
+- 1 RCU (Read Capacity Unit) = 1 or 2 read of <=4 kB ops per second
+  - read sizes are rounded up to 4kB: 1 r/sec of 500B counts as 1 RCU
+  - 2 types of reads for 1 RCU:
+    - eventually consistent: 2 read/sec
+    - strongly consistent: 1 read/sec
+
+DDB replicates all writes, and uses eventual consistency:
+
+- eventual consistency uses the most available replicate, and is good for
+  - data that may be stale
+  - apps that do not query soon after writing
+- strong consistency checks all replicas for the most recent update, and is food for
+  - data that must be up-to-date
+  - applications that have a pattern of reading after writing
+
+![eventual consistency](3-1-eventual-consistency.png)
+
+## 3.2 Calculating throughput capacity
+
+- DDB provides adjustement of WCU/RCU capacity with no downtime, by setting
+  minimum and maximum RCU/WCU expected for a table
+- To calculate these, we need:
+  - size of items in kB
+  - quantity of items read/written per second to the table
+  - required read consistency
+- Example: app reads 10 eventually consistent items/sec around 1kB each
+  - Round up item size to next 4kB -> 4kB = 1 Read Unit (RU)
+  - RU * rps: 1 * 10 = 10 RCU
+  - eventual consistency: divide RCU by 2 -> 5 RCU
+- Example: app reads 10 strongly consistent items/sec around 14kB each
+  - Round: 14kB -> 16kB = 4 RU
+  - RU * rps: 4 * 10 = 40 RCU
+  - strong consistency: don't divide -> 40 RCU
+- Example: app writes 10 items around (below) 7kB/second
+  - Round up : 7 -> 7 WU
+  - WU * rps: 7 * 10 = 70 WCU
+
+## 3.3 Table autoscaling
+
+- Apps which exceed capacity will have additional request throttled as fails
+- We don't want to over-provision constantly because of the cost
+- In that case use on-demand autoscaling instead of provisioned autoscaling
+
+|   Provisioned Autoscaling    |     On-demande Autoscaling      |
+|:----------------------------:|:-------------------------------:|
+| Predictable traffic patterns | Unpredictable traffic patterns  |
+| Pay for provisioned capacity |    Pay for amount of request    |
+|   Cap performand and price   | Unlimited performance and price |

+ 11 - 0
docker-compose.yml

@@ -0,0 +1,11 @@
+version: '3.8'
+services:
+  dynamodb-local:
+    command: "-jar DynamoDBLocal.jar -sharedDb -dbPath ./data"
+    image: "amazon/dynamodb-local:latest"
+    container_name: dynamodb-local
+    ports:
+      - "8000:8000"
+    volumes:
+      - "./docker/dynamodb:/home/dynamodblocal/data"
+    working_dir: /home/dynamodblocal

+ 9 - 0
glossary.md

@@ -0,0 +1,9 @@
+## R
+
+- RCU: Read Capacity Unit: 1 or 2RU/sec
+- RU: Read Unit. 4kB
+
+## W
+
+- WCU: Write Capacity Unit: 1 WU/sec
+- WU: Write Unit: 1kB

+ 3 - 0
go.mod

@@ -0,0 +1,3 @@
+module code.osinet.fr/fgm/dynamodb_demo
+
+go 1.18