반응형
블로그 이미지
개발자로서 현장에서 일하면서 새로 접하는 기술들이나 알게된 정보 등을 정리하기 위한 블로그입니다. 운 좋게 미국에서 큰 회사들의 프로젝트에서 컬설턴트로 일하고 있어서 새로운 기술들을 접할 기회가 많이 있습니다. 미국의 IT 프로젝트에서 사용되는 툴들에 대해 많은 분들과 정보를 공유하고 싶습니다.
솔웅

최근에 올라온 글

최근에 달린 댓글

최근에 받은 트랙백

글 보관함

카테고리

'2017/11/15'에 해당되는 글 1

  1. 2017.11.15 [AWS Certificate] Developer - DynamoDB Summary & Quiz


반응형

DynamoDB Summary



What is DynamoDB?


Amazon DynamoDB is a fast and flexible NoSQL database service for all applications that need consistent, single-digit millisecond latency at any scale. It is a fully managed database and supports both document and key-value data models. Its flexible data model and reliable performance make it a great fit for mobile, web, gaming, ad-tech, IoT, and many other applications.



Quick facts about DynamoDB


- Stored on SSD storage

- Spread Across 3 geographically distinct data centers


- Eventual Consistent Reads (Default)

  : Consistency across all copies of data is usually reached within a second. Repeating a read after a short time should return the updated data. (Best Read Performance)

  

- Strongly Consistent Reads

  : A strongly consistent read returns a result that reflects all writes that received a successful response prior to the read

  

  

The Basics


- Tables

- Items (Think a row of data in table)

- Attributes (Think of a column of data in a table)



DynamoDB - Primary Keys





Two Types of Primary Keys Avaliable


- Single Attribute (think unique ID)

  : Partition Key (Hash Key) composed of one attribute

  

- Composite (think unique ID and a date range)

  : Partition Key & Sort Key (Hash & Range) composed of two attributes.



  

- Partition Key

  : DynamoDB uses the partition key's value as input to an internal hash function. The output from the hash function determines the partition (this is simply the physical location in which the data is stored).

  : No two items in a table can have the same partition key value!

  

- Partition Key and Sort key

  : DynamoDB uses partition key's value as input to an internal hash function. The output from the hash function determines the partition (this is simply the physical location in which the data is stored)

  : Two items can have the same partition key, but they must have different sort key.

  : All items with the same partition key are stored together, in sorted order by sort key value.

  


DynamoDB - Indexes


- Local Secondary Index

  : Has the SAME partition key, different sort key.

  : Can ONLY be created when creating a table. They cannot be removed or modified later.



  

- Global Secondary Index

  : Has DIFFERENT Partition key and different sort key

  : Can be created at table creation or added LATER



  

  

DynamoDB - Streams


- Used to capture any kind of modification of the DynamoDB tables.

  : If a new item is added to the table, the stream captures an image of the entire item, including all of its attributes

  : If an item is updated, the stream captures the "before" and "after" image of any attributes that were modified in the item

  : If an item is deleted from the table, the stream captures an image of the entire item before it was deleted



  

  

Query & Scans Exam Tips


- A Query operation finds items in a table using only primary key attribute values. You must provide a partition key attribute name and a distinct value to search for.

- A Scan operation examines every item in the table. By default, a Scan returns all of the data attributes for every item, however, you can use the ProjectionExpression parameter so that the Scan only returns some of the attributes, rather than all of them.

- Try to use a query operation over a Scan operation as it is more efficient







Example 1


You have an application that requires to read 5 items of 10 KB per second using eventual consistency. What should you wet the read throughput to?


- First we  calculate how many read units per item we need

- 10 KB rounded up to nearest increment of 4 KB is 12 KB

- 12 KB / 4 KB = 3 read units per item


- 3 X 5 read items = 15

- Using eventual consistency we get 15/2 = 7.5


- 8 units of read throughput



Example 2 - Write THroughput


You have an application that requires to write 12 items of 100 KB per item each second. What should you set the write throughput to?


- Each write unit consist of 1 KB of data. You need to write 12 items per second with each item having 100 KB of data

- 12 X 100 KB = 1200 write units

- Write throughput of 1200 units



Erro Codes


400 HTTP Status Code - 

ProvisionedThroughputExceededException


You exceeded your maximum allowed provisioned throughput for a table or for one or more global secondary indexes.


 

Steps taken to authenticate


1. User Authenticates with ID provider (such as Facebook)

2. They are passed a Token by their ID provider

3. Your code calls AssumeRoleWithWebIdentity API and provides the providers token and specifies the ARN for the IAM Role

4. App can now access Dynamodb from between 15 minutes to 1 hour (default is 1 hour)



Conditional Writes.


If item = $10 then update to $12


Note that conditional writes are idempotent. This means that you can send the same conditional write request multiple times, but it will have no further effect on the item after the first time DynamoDB performs the specified update. For example, suppose you issue a request to update the price of a book item by 10%, with the expectation that the price is currently $20.

However, before you get a response, a network error occurs and you don't know whether your request was successful or not. Because a conditional update is an idempotent operation, you can send the same request again. and DynamoDB will update the price only if the current price is still $20.



Atomic Counters


DynamoDB supports atomic counters, where you use the UpdateItem operation to increment or decrement the value of an existing attribute without interfering with other write requests. (All write requests are applied in the order in which they were received.) For example, a web application might want to maintain a counter per visitor to their site. In this case, the application would need to increment this counter regardless of its current value.


Atomic Counter updates are not idempotent. This means that counter will increment each time you call UpdateItem. If you suspect that a previous request was unsuccessful, your application could retry the updateItem operation, however, this would risk updating the counter twice. This might be acceptable for a web site counter, because you can tolerate with slightly over- or under- counting the visitors. However, in a banking application, it would be safer to use a conditional update rather than an atomic counter.



Batch Operations


If your application needs to read multiple items, you can use the BatchGetItem API. A single BatchGetItem request can retrieve up to 1 MB of data, which can contain as many as 100 items, In addition, a single BatchGetItem request can retrieve items from multiple tables.



****** READ THE DYNAMODB FAQ ******


If you read one FAQ in preparing for this course, make sure it's the DynamoDB FAQ!!!!!





======================================


DynamoDB Quiz


- DynamoDB is a No-SQL database provided by AWS. - True

- You have a motion sensor which writes 600 items of data every minute. Each item consists of 5kb. Your application uses eventually consistent reads. What should you set the read throughput to ?

  : 600/60 = 10 items per second. 5kb rounded up = 8kb 8/4 = 2. 

  : 2 read per item. 2 X 10 = 20 reads per second. 

  : As the reads are Eventually consistent, 20/2 = 10

  ==> The answer is 10

- A scan is more efficient than a query in terms of performance - False

- What does the error "ProvisionedThroughputExceededException" mean in DynamoDB?

  : You exceeded your maximum allowed provisioned throughput for a table or for one or more global secondary indexes.

- You have a motion sensor which writes 600 items of data every minute. Each item consists of 5 kb. what should you set the write throughput to? : 50

- What is the API call to retrieve multiple items from a DynamoDB table?

  : BatchGetItem

- You have a motion sensor which writes 600 items of data every minute. Each item consists of 5kb. Your application uses strongly consistent read. What should you set read throughput to? 

  : 600/60 = 10 items per second

  : 5kb rounded to nearest 4 kb chunk is 8kb. 8/4 = 2 reads per item

  : 2 X 10 reads per second.

  ==> The answer is 20

- Using the AWS portal, you are trying to Scale DynamoDB past its preconfigured maximums. Which service can you increase by raising a ticket to AWS support?

  : http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Limits.html

  ==> Provisioned throughput limits

 - You have an application that needs to read 25 items of 13 kb in size per second. Your application uses eventually consistent reads. What should you set the read throughput to?

   : 13 kb - roundup to the nearrest 4kb = 16 kb. 16/4 = 4 reads per item

   : 25 items X 4 = 100

   : 100 / 2 = 50 (eventually consistent reads)

   ==> The answer is 50

- You have an application that needs to read 25 items of 13 kb in size per second. Your application uses strongly consistent reads. What should you set the read throughput to?

   : 13 kb - roundup to the nearrest 4kb = 16 kb. 16/4 = 4 reads per item

   : 25 items X 4 = 100 (Strongly consistent reads)

   ==> The answer is 100

   


=======================================




반응형
이전 1 다음