4 Nisan 2023 Salı

Amazon Web Service (AWS) DynamoDB - Hem Key-value Hem de Document-Oriented Çalışabilir

Giriş
Bir NoSQL veri tabanıdır, ancak multi-model'i destekler yani key-value system and a document store olarak kullanılabilir.
1. Key-value store olarak Cassandra, HBase, Redis ile rakip
2. Document DB olarak MongoDB ile rakip.

DynamoDB ilk olarak 2012 yılında piyasaya çıktı

Özellikleri şöyle

Açıklaması şöyle
DynamoDB is Amazon's answer to MongoDB, a NoSQL database that works on JSON documents. These databases rely heavily on nested data and do not enforce any strict schema unless the developer turns that option on. That means that DynamoDB is great for high-volume sites like a CMS or mobile apps with a lot of traffic. For example, both Major League Baseball and Duolingo make use of DynamoDB.
Pricing Model
1. throughput model : Kullanım miktarı tahmin edilir ve bu aşılamaz.
2. on-demand pricing model : Kullanım miktarına göre fiyatlandırılır

MongoDB vs DynamoDB 
- MongoDB en büyük document size olarak 16 MB'yi destekler. Bu DynamoDB'de 400 KB
- MongoDB C++ ile geliştirilmiştir. DynamoDB Java ile geliştirilmiştir

Primary Key 
Açıklaması şöyle
... it only allows three data types for primary keys: string, number, and binary. (It does support many different data types for other attributes within a table.)
Açıklaması şöyle
DynamoDB has a weird take on the concept of a primary key. You will have two keys to identify specific data:
Primary Key = Partition Key + Sort Key
Şeklen şöyle

Örnek
Tablo şöyle olabilir
      PRIMARY_KEY     SORT_KEY         OTHER_INFO
1.    ORDER#1234       PRODUCT#1      ProductName,Price etc
2.    ORDER#1234       INVOICE#1         InvoiceDate, PaymentInfo
3.    ORDER#1234       CUSTOMER#1   CustomerName, ShippingAddress
Value Type
Açıklaması şöyle
Dynamo DB stores the value in a JSON serialized format

Sütun Tipleri
Açıklaması şöyle
DynamoDB supports many different data types for attributes within a table. They can be categorized as follows:

1. Scalar Types – A scalar type can represent exactly one value. The scalar types are numberstringbinaryBoolean, and null.

2. Document Types – A document type can represent a complex structure with nested attributes, such as you would find in a JSON document. The document types are list and map.

3. Set Types – A set type can represent multiple scalar values. The set types are string setnumber set, and binary set.

Global Secondary Index
Eğer istediğimiz veri Primary Key dışındaysa bu index kullanılır. Tek problem her indeksin tek başına bir tablo olması

DynamoDB Disadvantages
Açıklaması şöyle
Size limit — item can only reach 400KB in size
Limited querying options (limited number of indices)
Throttling on burst throughput (and hot keys in certain situations)
create-table
Örnek
Şöyle yaparız
aws dynamodb --endpoint-url=http://localhost:4566 create-table \
    --table-name Music \
    --attribute-definitions \
        AttributeName=Artist,AttributeType=S \
        AttributeName=SongTitle,AttributeType=S \
    --key-schema \
        AttributeName=Artist,KeyType=HASH \
        AttributeName=SongTitle,KeyType=RANGE \
--provisioned-throughput \
        ReadCapacityUnits=10,WriteCapacityUnits=5
describe-table
Şöyle yaparız
aws --endpoint-url=http://localhost:4566 dynamodb describe-table 
--table-name Music | grep TableStatus
put-item
Şöyle yaparız
aws --endpoint-url=http://localhost:4566 dynamodb put-item \
  --table-name Music  \
  --item \
  '{"Artist": {"S": "No One You Know"}, "SongTitle": {"S": "Call Me Today"},
"AlbumTitle": {"S": "Somewhat Famous"}, "Awards": {"N": "1"}}'
scan
Şöyle yaparız
aws dynamodb scan --endpoint-url=http://localhost:4566 --table-name Music
Örnek
Açıklaması şöyle
Because DynamoDB is not relational and does not enforce ACID by default, it must use a modified version of standard SQL. Amazon has developed a query language called PartiQL which uses many SQL concepts but is built for highly nested data. The query below takes advantage of the key-value underpinnings of DynamoDB in a relatively SQL standard way.
Şöyle yaparız
UPDATE
    Music
SET
    AwardsWon = 1
SET
    AwardDetail = { 'Grammys': [ 2020, 2018 ] }
WHERE
    Artist = 'Acme Band'
    AND SongTitle = 'PartiQL Rocks'

Hiç yorum yok:

Yorum Gönder