O slideshow foi denunciado.
Seu SlideShare está sendo baixado. ×

Amazon DynamoDB 키 디자인 패턴

Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio

Confira estes a seguir

1 de 52 Anúncio

Amazon DynamoDB 키 디자인 패턴

Baixar para ler offline

최근 국내에도 글로벌 서비스나 급성장하는 웹 서비스를 쉽게 볼 수 있습니다. 초기에 RDBMS로 시작된 서비스들은 규모가 성장함에 따라 샤딩과 NoSQL의 선택의 기로에 서게 됩니다. Amazon DynamoDB는 모든 스케일에서 사용할 수 있는 완전 관리형 Key-Value NoSQL 데이터베이스이지만 여전히 Key Design은 가장 어려운 영역 중 하나입니다. 이 세션에서는 대규모 서비스의 키 디자인 방법을 알아봅니다.

최근 국내에도 글로벌 서비스나 급성장하는 웹 서비스를 쉽게 볼 수 있습니다. 초기에 RDBMS로 시작된 서비스들은 규모가 성장함에 따라 샤딩과 NoSQL의 선택의 기로에 서게 됩니다. Amazon DynamoDB는 모든 스케일에서 사용할 수 있는 완전 관리형 Key-Value NoSQL 데이터베이스이지만 여전히 Key Design은 가장 어려운 영역 중 하나입니다. 이 세션에서는 대규모 서비스의 키 디자인 방법을 알아봅니다.

Anúncio
Anúncio

Mais Conteúdo rRelacionado

Semelhante a Amazon DynamoDB 키 디자인 패턴 (20)

Mais de Amazon Web Services Korea (20)

Anúncio

Mais recentes (20)

Amazon DynamoDB 키 디자인 패턴

  1. 1. DYNAMODB 키 디자인 패턴 © 2022, Amazon Web Services, Inc. or its affiliates. © 2022, Amazon Web Services, Inc. or its affiliates. DynamoDB 키 디자인 패턴 이혁 DynamoDB Specialist SA AWS
  2. 2. DYNAMODB 키 디자인 패턴 © 2022, Amazon Web Services, Inc. or its affiliates. © 2022, Amazon Web Services, Inc. or its affiliates. 아젠다 2 • 중요 컨셉 • 제약 조건 • Tenet • 디자인 패턴 및 비정규화 • 싱글 테이블 디자인 예제 • AWS 전문가들과 함께 DynamoDB 시작하기
  3. 3. DYNAMODB 키 디자인 패턴 © 2022, Amazon Web Services, Inc. or its affiliates. © 2022, Amazon Web Services, Inc. or its affiliates. 중요 컨셉 3
  4. 4. DYNAMODB 키 디자인 패턴 © 2022, Amazon Web Services, Inc. or its affiliates. Partition Key(PK) 필수 Key-value 액세스 패턴 데이터 분포 결정 선택적 1:N 관계 모델링 다양한 쿼리 연산자 제공 A1 (partition key) A2 (sort key) Sort Key(SK) 테이블 아이템 A1 (partition key) A2 (sort key) A3 A4 A7 A1 (partition key) A2 (sort key) A6 A4 A5 A1 (partition key) A2 (sort key) A3 A4 A5 All items for a partition key ==, <, >, >=, <= “begins with” “between” sorted results counts top/bottom N values paged responses DynamoDB 테이블 구조
  5. 5. DYNAMODB 키 디자인 패턴 © 2022, Amazon Web Services, Inc. or its affiliates. Primary key의 중요성 쿼리 가능 쿼리 불가능
  6. 6. DYNAMODB 키 디자인 패턴 © 2022, Amazon Web Services, Inc. or its affiliates. 전통적인 RDBMS NoSQL DB DB 스케일 업 DB P1 DB Pn DB P2 DB P3 많은 샤드로 스케일 아웃 기본 전제: 수평으로 확장 가능한 데이터를 설계하는 방법이 있다. 데이터베이스 스케일링
  7. 7. DYNAMODB 키 디자인 패턴 © 2022, Amazon Web Services, Inc. or its affiliates. Server 1 T1.p1 테이블 1 테이블 2 테이블 3 Server N T1.pn 테이블 단위로 작업하시면.. 최대 1K WCU 3K RCU 10 GB DynamoDB는 나머지를 내부적으로 처리합니다..
  8. 8. DYNAMODB 키 디자인 패턴 © 2022, Amazon Web Services, Inc. or its affiliates. DynamoDB 수평적 스케일링 워크로드: 데이터 볼륨, 읽기, 쓰기 DynamoDB 리소스: 스토리지, 읽기&쓰기 용량
  9. 9. DYNAMODB 키 디자인 패턴 © 2022, Amazon Web Services, Inc. or its affiliates. Hash(1) = 7B Orders 00 55 AA FF Partition A Partition B Partition C Hash.MIN = 0 Hash.MAX = FF Keyspace Hash(2) = 48 Hash(3) = CD DynamoDB table OrderId: 1 CountryCode: 1 ASIN: [B00X4WHP5E] OrderId: 2 CountryCode : 1 ASIN: [B00OQVZDJM] OrderId: 3 CountryCode : 1 ASIN: [B00U3FPN4U] Aggregates Partition key 아이템 분포 (이상적 경우)
  10. 10. DYNAMODB 키 디자인 패턴 © 2022, Amazon Web Services, Inc. or its affiliates. Availability Zone A Partition A Host 4 Host 6 Availability Zone B Availability Zone C Partition A Partition A Partition C Partition C Partition C Host 5 Partition B Host 1 Host 3 Host 2 Partition B Host 7 Host 9 Host 8 Partition B CustomerOrdersTable • 데이터는 항상 3개의 가용 영역에 복제됩니다. • 서비스는 3개의 가용 영역에서 실행됩니다. 세 벌 복제 OrderId: 1 CustomerId: 1 ASIN: [B00X4WHP5E] Hash(1) = 7B Partition A 다른 각도에서 보기
  11. 11. DYNAMODB 키 디자인 패턴 © 2022, Amazon Web Services, Inc. or its affiliates. © 2022, Amazon Web Services, Inc. or its affiliates. 제약 조건 11
  12. 12. DYNAMODB 키 디자인 패턴 © 2022, Amazon Web Services, Inc. or its affiliates. 스케일링 • 처리량 ▪ 테이블에 원하는 양의 처리량 설정 ▪ RCU(Read Capacity Unit) : 4 KB per second(프로비전드) or request(온디맨드) ▪ WCU(Write Capacity Unit) : 1 KB per second(프로비전드) or request(온디맨드) ▪ RCU와 WCU는 독립적으로 동작 ▪ Eventually Consistent 읽기는 Strongly Consistent 읽기에 비해 RCU를 절반만 사용: 8 KB per second(프로비전드) or request(온디맨드) 12
  13. 13. DYNAMODB 키 디자인 패턴 © 2022, Amazon Web Services, Inc. or its affiliates. 스케일링 • 사이즈 ▪ 테이블에 아이템을 원하는 수만큼 추가 가능 – 아이템의 최대 크기는 400 KB – 하지만, 400 KB를 모두 사용하는 것은 비권장 • 스케일링은 파티셔닝을 통해 이루어짐 ▪ 각 파티션은 1,000 WCU/초 혹은 3,000 RCU/초를 제공하여 둘 중 하나가 초과되면 파티션이 늘어나는 구조 ▪ 데이터 용량이 10GB 초과 시 파티션이 늘어나는 구조 13
  14. 14. DYNAMODB 키 디자인 패턴 © 2022, Amazon Web Services, Inc. or its affiliates. DynamoDB에서 데이터 읽는 방법(REST API) • GetItem ▪ Partition key의 정확한 값 지정 ▪ 정확히 0 또는 1개의 아이템을 반환 ▪ 아이템 크기에 따라 RCU를 사용 • Query ▪ Partition key의 정확한 값 지정 ▪ 선택적으로 non-key 어트리뷰트에 필터링 조건 추가 ▪ 일치하는 아이템 반환(여러 개 가능) ▪ Key 조건과 일치하는 아이템의 크기에 따라 RCU를 소비하여 단일 결과를 반환 14
  15. 15. DYNAMODB 키 디자인 패턴 © 2022, Amazon Web Services, Inc. or its affiliates. DynamoDB에서 데이터 읽는 방법(REST API) • Scan ▪ 키를 지정하지 마세요! 선택적으로 키가 아닌 어트리뷰트에 대한 필터 조건 지정 ▪ 필터 표현식과 일치하는 테이블의 모든 아이템을 반환 ▪ 테이블의 모든 아이템을 읽기 위해 RCU를 소비합니다. 운영 환경에서 사용을 주의 깊게 생각하세요. 15
  16. 16. DYNAMODB 키 디자인 패턴 © 2022, Amazon Web Services, Inc. or its affiliates. • Query & Scan ▪ 단일 호출로 최대 1MB를 반환하며, 응답 메시지가 1MB 이상 시 LastEvaluatedKey을 이용해 pagination 가능 • BatchGetItem ▪ 단일 호출로 최대 100개 아이템 혹은 최대 16MB 반환 • BatchWriteItem ▪ 단일 호출로 최대 25 PutItem 혹은 DeleteItem 수행하며 최대 16MB 쓰기 16 대표적인 API 제약 조건
  17. 17. DYNAMODB 키 디자인 패턴 © 2022, Amazon Web Services, Inc. or its affiliates. 데이터 타입 Data Type DynamoDB Type String String Integer, Float Number Timestamp Number or String Blob Binary Boolean Bool Null Null List List Set Set of String, Number, or Binary Map Map Data Operations GetItem Query Scan BatchGetItem PutItem UpdateItem DeleteItem BatchWriteItem TransactGetItems TransactWriteItems 데이터 조작
  18. 18. DYNAMODB 키 디자인 패턴 © 2022, Amazon Web Services, Inc. or its affiliates. 대체 Partition 및/또는 Sort key 인덱스는 모든 Partition key에 있음 A2 (partition) A1 (sort) A1 (partition) A2 (sort) A3 A4 A5 A6 GSIs A5 (partition) A4 (sort) A1 (item key) A2 (item key) A3 (projected) 테이블 KEYS_ONLY INCLUDE A3 A4 (partition) A5 (sort) A1 (item key) A2 (item key) A3 (projected) A6 (projected ALL 베이스 테이블의 PK/SK는 아이템의 유니크함을 위해 자동으로 복사 GSI(Global Secondary Index)
  19. 19. DYNAMODB 키 디자인 패턴 © 2022, Amazon Web Services, Inc. or its affiliates. A1 (PK) A3 (LSI-SK) A2 (SK) A1 (PK) A2 (SK) A3 A4 A5 LSIs A1 (PK) A4 (LSI-SK) A2 (SK) A3 (projected) Table KEYS_ONLY INCLUDE A3 A1 (PK) A5 (LSI-SK) A2 (SK) A3 (projected) A4 (projected) ALL 베이스 테이블의 Sort key는 자동으로 복사됨 LSI(Local Secondary Index)
  20. 20. DYNAMODB 키 디자인 패턴 © 2022, Amazon Web Services, Inc. or its affiliates. LSI GSI 테이블 생성 시에만 가능 언제든 생성 및 삭제 가능 베이스 테이블과 WCU/RCU 공유 베이스 테이블과 별도의 WCU/RCU Collection size <= 10GB No size limits Limit = 5 Limit = 20 Strong Consistency Eventual Consistency LSI vs GSI
  21. 21. DYNAMODB 키 디자인 패턴 © 2022, Amazon Web Services, Inc. or its affiliates. © 2022, Amazon Web Services, Inc. or its affiliates. Tenet 21
  22. 22. DYNAMODB 키 디자인 패턴 © 2022, Amazon Web Services, Inc. or its affiliates. SQL vs. NoSQL 디자인 패턴
  23. 23. DYNAMODB 키 디자인 패턴 © 2022, Amazon Web Services, Inc. or its affiliates. • Use case 정의 • 액세스 패턴을 식별 • 읽기/쓰기 워크로드 • 쿼리 차원 • 집계 • 데이터 모델링 • 관계형 디자인 패턴을 피한다 • 하나의 테이블로 시작한다 • 애플리케이션 종류: OLTP vs OLAP • 데이터 라이프 사이클 • TTL, Backup/Archival 등. • Primary Keys 식별 • 어떻게 읽고 쓰는가? Review -> Repeat -> Review DynamoDB 데이터 모델링 TENET
  24. 24. DYNAMODB 키 디자인 패턴 © 2022, Amazon Web Services, Inc. or its affiliates. © 2022, Amazon Web Services, Inc. or its affiliates. 디자인 패턴 및 비정규화 24
  25. 25. DYNAMODB 키 디자인 패턴 © 2022, Amazon Web Services, Inc. or its affiliates. 비정규화 • DynamoDB가 잘 하는 것 ▪ 무한하게 많은 아이템 중에 하나 혹은 몇개를 일정한 시간에 찾아낸다. • RDBMS ▪ 데이터 액세스 패턴을 고민하기보다 데이터 모델 정규화 노력 ▪ Ad-hoc 쿼리 가능 • DynamoDB ▪ 모든 데이터 액세스 패턴을 알고 시작 ▪ Pre-computation 필요 25
  26. 26. DYNAMODB 키 디자인 패턴 © 2022, Amazon Web Services, Inc. or its affiliates. 간단한 PK 유일키 • 사용자 프로파일 • 세션 스토어 • 상품 정보 26
  27. 27. DYNAMODB 키 디자인 패턴 © 2022, Amazon Web Services, Inc. or its affiliates. + = PK+SK 복합키
  28. 28. DYNAMODB 키 디자인 패턴 © 2022, Amazon Web Services, Inc. or its affiliates. PK+SK 복합키 • SK(Sort key) ▪ 많이 사용되는 값 – 알파벳, 숫자, 타임스탬프, ULID/KSUID ▪ 오름차순, 내림차순 조회 가능 • 예제 ▪ IoT 로그 ▪ 소셜 네트워크의 포스트 리스트 ▪ 주문 상세정보 혹은 이력 등 28
  29. 29. DYNAMODB 키 디자인 패턴 © 2022, Amazon Web Services, Inc. or its affiliates. PK+SK 복합키 예제 29
  30. 30. DYNAMODB 키 디자인 패턴 © 2022, Amazon Web Services, Inc. or its affiliates. PK+SK 복합키 예제 30
  31. 31. DYNAMODB 키 디자인 패턴 © 2022, Amazon Web Services, Inc. or its affiliates. 싱글 테이블 디자인 • 정의 ▪ 모든 엔티티를 하나의 테이블로 설계하는 방법 • 장점 ▪ 적은 운영 부담 ▪ 높은 테이블 최대 성능 및 쓰로틀링 경감 • 단점 ▪ 높은 러닝 커브 ▪ 예외 케이스 : 시계열, 다른 액세스 패턴의 엔티티 31
  32. 32. DYNAMODB 키 디자인 패턴 © 2022, Amazon Web Services, Inc. or its affiliates. 싱글 테이블 디자인 • 안티 패턴 ▪ PK를 UserID로 고정하고 시작하는 습관 – 일반 사용자와 VIP를 같은 키 디자인으로 해결하려는 습관 – 대량 트래픽을 유발하는 heavy user를 항상 고민해야함 ▪ 엔티티 별로 테이블을 만들려는 습관 ▪ GSI를 많이 사용하려는 습관 32
  33. 33. DYNAMODB 키 디자인 패턴 © 2022, Amazon Web Services, Inc. or its affiliates. © 2022, Amazon Web Services, Inc. or its affiliates. 싱글 테이블 디자인 예제 - 이커머스 애플리케이션 디자인 33
  34. 34. DYNAMODB 키 디자인 패턴 © 2022, Amazon Web Services, Inc. or its affiliates. 키 디자인 풀사이클 • 비즈니스 유즈 케이스 이해하기 • ER 다이어그램 그리기 • 모든 데이터 액세스 패턴 정리하기 • 키 디자인 시작하기
  35. 35. DYNAMODB 키 디자인 패턴 © 2022, Amazon Web Services, Inc. or its affiliates. … A customer visits an online shop, browses through different products and places an order for some of the products. Based on the invoice, customer can pay using discount code or gift card and pay for the remaining amount by credit card. Purchased products will be picked from one or several warehouses and will be shipped to the provided address. … https://github.com/aws-samples/amazon-dynamodb-design-patterns/tree/master/examples/an-online-shop 비즈니스 유즈 케이스 이해하기
  36. 36. DYNAMODB 키 디자인 패턴 © 2022, Amazon Web Services, Inc. or its affiliates. ER 다이어그램 그리기
  37. 37. DYNAMODB 키 디자인 패턴 © 2022, Amazon Web Services, Inc. or its affiliates. # 액세스 패턴 1 Get customer for a given customerId 2 Get product for a given productId 3 Get warehouse for a given warehouseId 4 Get a product inventory for all warehouses by a productId 5 Get all order details for a given orderId 6 Get all products for a given orderId 7 Get invoice for a given orderId 8 Get all shipments for a given orderId 모든 데이터 액세스 패턴 정리하기
  38. 38. DYNAMODB 키 디자인 패턴 © 2022, Amazon Web Services, Inc. or its affiliates. # Access Patterns Table/ GSI/LSI Key Condition Filter Expression Example 1 Get customer for a given customerId Table PK=customerId SK=customerId - PK="c#12345” SK="c#12345" 2 Get product for a given productId Table PK=productId SK=productId - PK="p#12345" SK="p#12345" 3 Get warehouse for a given warehouseId Table PK=warehouseId SK=warehouseId - PK=”w#12345" SK=”w#12345" 키 디자인 시작하기
  39. 39. DYNAMODB 키 디자인 패턴 © 2022, Amazon Web Services, Inc. or its affiliates. 키 디자인 시작하기
  40. 40. DYNAMODB 키 디자인 패턴 © 2022, Amazon Web Services, Inc. or its affiliates. # Access Patterns Table/ GSI/LSI Key Condition Filter Expression Example 4 Get a product inventory for all warehouses by a productId Table PK=productid SK begins_with "w#" - PK="p#12345” SK begins_with "w#" 키 디자인 시작하기
  41. 41. DYNAMODB 키 디자인 패턴 © 2022, Amazon Web Services, Inc. or its affiliates. 키 디자인 시작하기
  42. 42. DYNAMODB 키 디자인 패턴 © 2022, Amazon Web Services, Inc. or its affiliates. # Access Patterns Table/ GSI/LSI Key Condition Filter Expression Example 5 Get all order details for a given orderId Table PK=orderId - PK="o#12345" 6 Get all products for a given orderId Table PK=orderId SK begins_with "p#" - PK="o#12345" SK begins_with "p#" 키 디자인 시작하기
  43. 43. DYNAMODB 키 디자인 패턴 © 2022, Amazon Web Services, Inc. or its affiliates. 키 디자인 시작하기
  44. 44. DYNAMODB 키 디자인 패턴 © 2022, Amazon Web Services, Inc. or its affiliates. # Access Patterns Table/ GSI/LSI Key Condition Filter Expression Example 7 Get invoice for a given orderId Table PK=orderId SK begins_with "i#" - PK="o#12345" SK begins_with "i#" 키 디자인 시작하기
  45. 45. DYNAMODB 키 디자인 패턴 © 2022, Amazon Web Services, Inc. or its affiliates. 키 디자인 시작하기
  46. 46. DYNAMODB 키 디자인 패턴 © 2022, Amazon Web Services, Inc. or its affiliates. # Access Patterns Table/ GSI/LSI Key Condition Filter Expression Example 8 Get all shipments for a given orderId Table PK=orderId SK begins_with "sh#" - PK="o#12345" SK begins_with "sh#" 키 디자인 시작하기
  47. 47. DYNAMODB 키 디자인 패턴 © 2022, Amazon Web Services, Inc. or its affiliates. 키 디자인 시작하기
  48. 48. DYNAMODB 키 디자인 패턴 © 2022, Amazon Web Services, Inc. or its affiliates. # Access Patterns Table/GSI/LSI Key Condition Filter Expression Example 1 Get customer for a given customerId Table PK=customerId AND SK=customerId - PK="c#12345” AND SK="c#12345" 2 Get product for a given productId Table PK=productid AND SK=productId - PK="p#12345” AND SK="p#12345" 3 Get warehouse for a given warehouseId Table PK=warehouseId AND SK=warehouseId - PK=”w#12345” AND SK=”w#12345" 4 Get a product inventory for all warehouses by a productId Table PK=productid SK begins_with "w#" - PK="p#12345” SK begins_with "w#" 5 Get all order details for a given orderId Table PK=orderId - PK="o#12345" 6 Get all products for a given orderId Table PK=orderId SK begins_with "p#" - PK="o#12345" SK begins_with "p#" 7 Get invoice for a given orderId Table PK=orderId SK begins_with "i#" - PK="o#12345" SK begins_with "i#" 8 Get all shipments for a given orderId Table PK=orderId SK begins_with "sh#" - PK="o#12345" SK begins_with "sh#" 키 디자인 시작하기
  49. 49. DYNAMODB 키 디자인 패턴 © 2022, Amazon Web Services, Inc. or its affiliates. © 2022, Amazon Web Services, Inc. or its affiliates. AWS 전문가들과 함께 DynamoDB 시작하기 49
  50. 50. DYNAMODB 키 디자인 패턴 © 2022, Amazon Web Services, Inc. or its affiliates. DynamoDB Immersion Day • 하루 전일 대면 교육(09:00 – 17:00) • 개발자를 우선으로 타겟팅된 키 디자인 중심 교육 • AWS Account Team을 통해 요청 기반으로 전달
  51. 51. DYNAMODB 키 디자인 패턴 © 2022, Amazon Web Services, Inc. or its affiliates. DCAD(Database Clinic in A Day) 프로그램 • DynamoDB Immersion Day 교육 이수 조건 • DynamoDB 전문가들과 함께 실제 고객 워크로드를 진단해보는 반일과정 워크샵 • 키 디자인, 성능, 비용 최적화 등의 주제로 DynamoDB를 사용하며 발생하는 고객의 pain point를 함께 풀어보는 시간 • AWS Account Team을 통해 요청 기반으로 전달
  52. 52. DYNAMODB 키 디자인 패턴 © 2022, Amazon Web Services, Inc. or its affiliates. Thank you! © 2022, Amazon Web Services, Inc. or its affiliates. 이혁 hyuklee@amazon.com

×