[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M79DWCG7T1HPDQ59PD0CJBKK":3,"skill-same:01M79DWCG7T1HPDQ59PD0CJBKK":48},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":18,"publishedAt":19,"linkOnly":20,"markdownContent":21,"markdownBody":22,"frontMatter":23,"refName":24,"commitSha":25,"skillDirectory":26,"forksCount":27,"repositoryHtmlUrl":28,"repositoryHomepageUrl":29,"ownerHtmlUrl":30,"ownerBlogUrl":31,"ownerDescription":32,"updatedAt":33,"install":34,"resources":47},"01M79DWCG7T1HPDQ59PD0CJBKK","dynamodb-single-table-design",null,"Advanced Amazon DynamoDB Single-Table Design patterns, access pattern modeling, Partition Key (PK) and Sort Key (SK) strategies, Global Secondary Indexes (GSIs), sparse indexes, and transactions. Use when designing high-scale DynamoDB data layers.","hamzabellouch\u002Fagent-skills","hamzabellouch","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F237856042?v=4","01M79BRYW7XAMK3YDWQEMTWGWS","Hamza Bellouch","01M79BRYWXQV3JK2TGVTX8GN2A",8,"MIT","https:\u002F\u002Fgithub.com\u002Fhamzabellouch\u002Fagent-skills\u002Fblob\u002Fmain\u002FProgramming\u002FBackend\u002FDatabases_and_Caching\u002Fdynamodb-single-table-design\u002FSKILL.md",[],[],"2026-11-15 14:19:17",false,"---\nname: dynamodb-single-table-design\ndescription: Advanced Amazon DynamoDB Single-Table Design patterns, access pattern modeling, Partition Key (PK) and Sort Key (SK) strategies, Global Secondary Indexes (GSIs), sparse indexes, and transactions. Use when designing high-scale DynamoDB data layers.\n---\n\n# DynamoDB Single-Table Design Architecture Guide\n\nComprehensive reference for mastering Amazon DynamoDB Single-Table Design, access pattern modeling, secondary index overloading, sparse indexes, and high-concurrency transactional operations.\n\n---\n\n## 1. Principles of Single-Table Design\n\n### Why Single-Table Design?\nIn DynamoDB, microsecond-latency scale is achieved by avoiding runtime joins. Instead of creating separate tables for each entity type, a Single-Table Design pre-joins heterogenous entities into a single physical table using generic Partition Keys (`PK`) and Sort Keys (`SK`).\n\n```\n+-------------------+--------------------+------------------------+------------------+\n| PK                | SK                 | Type                   | Data Payload     |\n+-------------------+--------------------+------------------------+------------------+\n| USER#usr_1001     | METADATA           | UserProfile            | { name, email }  |\n| USER#usr_1001     | ORDER#2026-07-01   | Order                  | { total: 49.99 } |\n| USER#usr_1001     | ORDER#2026-07-18   | Order                  | { total: 89.00 } |\n| ORDER#ord_9901    | METADATA           | Order                  | { status: SHIPPED|\n+-------------------+--------------------+------------------------+------------------+\n```\n\n### Access Pattern Driven Design Workflow\n1. **List all access patterns** (Reads, Writes, Aggregations) *before* defining keys.\n2. Design Primary Partition Keys (`PK`) to group related items into logical item collections.\n3. Design Primary Sort Keys (`SK`) to enable range filtering (`begins_with`, `BETWEEN`).\n4. Add Global Secondary Indexes (GSIs) for alternate access vectors.\n\n---\n\n## 2. Primary Key & Composite Sort Key Conventions\n\n### Common Key Formatting Conventions\n\n* **User Entity**: `PK: USER#\u003CuserId>`, `SK: METADATA`\n* **User Orders**: `PK: USER#\u003CuserId>`, `SK: ORDER#\u003Ctimestamp>#\u003CorderId>`\n* **Order Details**: `PK: ORDER#\u003CorderId>`, `SK: METADATA`\n* **Order Line Items**: `PK: ORDER#\u003CorderId>`, `SK: ITEM#\u003ClineItemId>`\n\n### Hierarchical Querying via Composite Keys\nSort keys can store hierarchical values separated by delimiters (`#` or `#STATUS#`):\n\n```typescript\n\u002F\u002F Sort Key pattern: STATUS#\u003Cstatus>#DATE#\u003Cdate>\n\u002F\u002F Example SK value: STATUS#PENDING#DATE#2026-07-18\n\n\u002F\u002F Access Pattern: Fetch all PENDING orders for a store created today\nQueryInput = {\n  KeyConditionExpression: \"PK = :pk AND begins_with(SK, :skPrefix)\",\n  ExpressionAttributeValues: {\n    \":pk\": \"STORE#store_880\",\n    \":skPrefix\": \"STATUS#PENDING#DATE#2026-07-18\"\n  }\n}\n```\n\n---\n\n## 3. Modeling Relationships & Secondary Indexes\n\n### 3.1 1:N Relationships (Item Collections)\nFetch both parent metadata and child items in a single $O(1)$ `Query` operation:\n\n```typescript\n\u002F\u002F Query PK = \"USER#usr_1001\" returns:\n\u002F\u002F 1. User Profile item (SK = \"METADATA\")\n\u002F\u002F 2. All user orders (SK starts with \"ORDER#\")\n```\n\n### 3.2 N:M Relationships (Adjacency List Pattern)\nModel many-to-many associations (e.g., Users and Groups) using primary keys for forward lookup and an inverted GSI for reverse lookup.\n\n| Index | PK | SK | Target Entity |\n| :--- | :--- | :--- | :--- |\n| **Base Table** | `USER#usr_1` | `GROUP#grp_100` | User Membership |\n| **GSI1 (Inverted)** | `GROUP#grp_100` | `USER#usr_1` | Reverse Group Roster |\n\n### 3.3 Sparse Indexes for State Filtering\nGSIs only index items containing the index attributes. Omitting GSI key fields for items in non-target states creates a low-cost, ultra-efficient **Sparse Index**.\n\n```typescript\n\u002F\u002F Only items with GSI1PK set (e.g. orders requiring review) appear in GSI1\nconst orderNeedingReview = {\n  PK: \"ORDER#ord_505\",\n  SK: \"METADATA\",\n  GSI1PK: \"ORDERS_PENDING_REVIEW\",\n  GSI1SK: \"2026-07-18T14:30:00Z\",\n  status: \"FLAGGED\"\n};\n```\n\n---\n\n## 4. Concurrency Control, Transactions & TTL\n\n### Optimistic Locking via Condition Expressions\nPrevent race conditions during concurrent write operations without table locking:\n\n```typescript\nimport { DynamoDBClient } from '@aws-sdk\u002Fclient-dynamodb';\nimport { DynamoDBDocumentClient, UpdateCommand } from '@aws-sdk\u002Flib-dynamodb';\n\nconst ddocClient = DynamoDBDocumentClient.from(new DynamoDBClient({}));\n\nasync function updateAccountBalance(accountId: string, amount: number, currentVersion: number) {\n  const command = new UpdateCommand({\n    TableName: 'SingleTableApp',\n    Key: {\n      PK: `ACCOUNT#${accountId}`,\n      SK: 'METADATA'\n    },\n    UpdateExpression: 'SET balance = balance + :val, version = version + :inc',\n    ConditionExpression: 'version = :expectedVersion AND balance >= :minBalance',\n    ExpressionAttributeValues: {\n      ':val': amount,\n      ':inc': 1,\n      ':expectedVersion': currentVersion,\n      ':minBalance': Math.abs(amount)\n    }\n  });\n\n  return await ddocClient.send(command);\n}\n```\n\n---\n\n## 5. Anti-Patterns & Common Pitfalls\n\n* ❌ **Relational Mindset (Multi-Table Sprawl)**: Creating a table for every entity type. Increases latency and operational overhead.\n* ❌ **Using `Scan` in Production API Endpoints**: Reads every partition sequentially. Causes extreme cost and request throttling. **Always use `Query` or `GetItem`**.\n* ❌ **Hot Partitions**: Structuring `PK` using low-cardinality values (e.g., `PK: GENDER#MALE`). Reaches partition IOPS limits ($1,000$ write units\u002Fsec or $3,000$ read units\u002Fsec per partition).\n* ❌ **Unbounded Item Sizes**: Storing growing arrays inside a single item until reaching the $400\\text{ KB}$ DynamoDB item hard limit. Split array items across sort keys instead.\n* ❌ **Unnecessary `ProjectionExpression: ALL` on GSIs**: Duplicates all attribute data into secondary index storage, driving up AWS billable write units. Use `KEYS_ONLY` or `INCLUDE` where possible.\n","# DynamoDB Single-Table Design Architecture Guide\n\nComprehensive reference for mastering Amazon DynamoDB Single-Table Design, access pattern modeling, secondary index overloading, sparse indexes, and high-concurrency transactional operations.\n\n---\n\n## 1. Principles of Single-Table Design\n\n### Why Single-Table Design?\nIn DynamoDB, microsecond-latency scale is achieved by avoiding runtime joins. Instead of creating separate tables for each entity type, a Single-Table Design pre-joins heterogenous entities into a single physical table using generic Partition Keys (`PK`) and Sort Keys (`SK`).\n\n```\n+-------------------+--------------------+------------------------+------------------+\n| PK                | SK                 | Type                   | Data Payload     |\n+-------------------+--------------------+------------------------+------------------+\n| USER#usr_1001     | METADATA           | UserProfile            | { name, email }  |\n| USER#usr_1001     | ORDER#2026-07-01   | Order                  | { total: 49.99 } |\n| USER#usr_1001     | ORDER#2026-07-18   | Order                  | { total: 89.00 } |\n| ORDER#ord_9901    | METADATA           | Order                  | { status: SHIPPED|\n+-------------------+--------------------+------------------------+------------------+\n```\n\n### Access Pattern Driven Design Workflow\n1. **List all access patterns** (Reads, Writes, Aggregations) *before* defining keys.\n2. Design Primary Partition Keys (`PK`) to group related items into logical item collections.\n3. Design Primary Sort Keys (`SK`) to enable range filtering (`begins_with`, `BETWEEN`).\n4. Add Global Secondary Indexes (GSIs) for alternate access vectors.\n\n---\n\n## 2. Primary Key & Composite Sort Key Conventions\n\n### Common Key Formatting Conventions\n\n* **User Entity**: `PK: USER#\u003CuserId>`, `SK: METADATA`\n* **User Orders**: `PK: USER#\u003CuserId>`, `SK: ORDER#\u003Ctimestamp>#\u003CorderId>`\n* **Order Details**: `PK: ORDER#\u003CorderId>`, `SK: METADATA`\n* **Order Line Items**: `PK: ORDER#\u003CorderId>`, `SK: ITEM#\u003ClineItemId>`\n\n### Hierarchical Querying via Composite Keys\nSort keys can store hierarchical values separated by delimiters (`#` or `#STATUS#`):\n\n```typescript\n\u002F\u002F Sort Key pattern: STATUS#\u003Cstatus>#DATE#\u003Cdate>\n\u002F\u002F Example SK value: STATUS#PENDING#DATE#2026-07-18\n\n\u002F\u002F Access Pattern: Fetch all PENDING orders for a store created today\nQueryInput = {\n  KeyConditionExpression: \"PK = :pk AND begins_with(SK, :skPrefix)\",\n  ExpressionAttributeValues: {\n    \":pk\": \"STORE#store_880\",\n    \":skPrefix\": \"STATUS#PENDING#DATE#2026-07-18\"\n  }\n}\n```\n\n---\n\n## 3. Modeling Relationships & Secondary Indexes\n\n### 3.1 1:N Relationships (Item Collections)\nFetch both parent metadata and child items in a single $O(1)$ `Query` operation:\n\n```typescript\n\u002F\u002F Query PK = \"USER#usr_1001\" returns:\n\u002F\u002F 1. User Profile item (SK = \"METADATA\")\n\u002F\u002F 2. All user orders (SK starts with \"ORDER#\")\n```\n\n### 3.2 N:M Relationships (Adjacency List Pattern)\nModel many-to-many associations (e.g., Users and Groups) using primary keys for forward lookup and an inverted GSI for reverse lookup.\n\n| Index | PK | SK | Target Entity |\n| :--- | :--- | :--- | :--- |\n| **Base Table** | `USER#usr_1` | `GROUP#grp_100` | User Membership |\n| **GSI1 (Inverted)** | `GROUP#grp_100` | `USER#usr_1` | Reverse Group Roster |\n\n### 3.3 Sparse Indexes for State Filtering\nGSIs only index items containing the index attributes. Omitting GSI key fields for items in non-target states creates a low-cost, ultra-efficient **Sparse Index**.\n\n```typescript\n\u002F\u002F Only items with GSI1PK set (e.g. orders requiring review) appear in GSI1\nconst orderNeedingReview = {\n  PK: \"ORDER#ord_505\",\n  SK: \"METADATA\",\n  GSI1PK: \"ORDERS_PENDING_REVIEW\",\n  GSI1SK: \"2026-07-18T14:30:00Z\",\n  status: \"FLAGGED\"\n};\n```\n\n---\n\n## 4. Concurrency Control, Transactions & TTL\n\n### Optimistic Locking via Condition Expressions\nPrevent race conditions during concurrent write operations without table locking:\n\n```typescript\nimport { DynamoDBClient } from '@aws-sdk\u002Fclient-dynamodb';\nimport { DynamoDBDocumentClient, UpdateCommand } from '@aws-sdk\u002Flib-dynamodb';\n\nconst ddocClient = DynamoDBDocumentClient.from(new DynamoDBClient({}));\n\nasync function updateAccountBalance(accountId: string, amount: number, currentVersion: number) {\n  const command = new UpdateCommand({\n    TableName: 'SingleTableApp',\n    Key: {\n      PK: `ACCOUNT#${accountId}`,\n      SK: 'METADATA'\n    },\n    UpdateExpression: 'SET balance = balance + :val, version = version + :inc',\n    ConditionExpression: 'version = :expectedVersion AND balance >= :minBalance',\n    ExpressionAttributeValues: {\n      ':val': amount,\n      ':inc': 1,\n      ':expectedVersion': currentVersion,\n      ':minBalance': Math.abs(amount)\n    }\n  });\n\n  return await ddocClient.send(command);\n}\n```\n\n---\n\n## 5. Anti-Patterns & Common Pitfalls\n\n* ❌ **Relational Mindset (Multi-Table Sprawl)**: Creating a table for every entity type. Increases latency and operational overhead.\n* ❌ **Using `Scan` in Production API Endpoints**: Reads every partition sequentially. Causes extreme cost and request throttling. **Always use `Query` or `GetItem`**.\n* ❌ **Hot Partitions**: Structuring `PK` using low-cardinality values (e.g., `PK: GENDER#MALE`). Reaches partition IOPS limits ($1,000$ write units\u002Fsec or $3,000$ read units\u002Fsec per partition).\n* ❌ **Unbounded Item Sizes**: Storing growing arrays inside a single item until reaching the $400\\text{ KB}$ DynamoDB item hard limit. Split array items across sort keys instead.\n* ❌ **Unnecessary `ProjectionExpression: ALL` on GSIs**: Duplicates all attribute data into secondary index storage, driving up AWS billable write units. Use `KEYS_ONLY` or `INCLUDE` where possible.\n",{"name":5,"description":7},"main","e905af21e5f1e1c3ca605e9656c3a7930360a84e","Programming\u002FBackend\u002FDatabases_and_Caching\u002Fdynamodb-single-table-design",1,"https:\u002F\u002Fgithub.com\u002Fhamzabellouch\u002Fagent-skills","https:\u002F\u002Fhamzabellouch.github.io\u002F","https:\u002F\u002Fgithub.com\u002Fhamzabellouch","hamzabellouch.github.io","CEO & Founder of @tknoglobal | Researcher in Technology & Applied Sciences.","2026-10-17 03:20:19",{"source":8,"skillName":5,"commands":35,"prompt":45,"zipAvailable":46},[36,39,42],{"tool":37,"command":38},"npx","npx skills add hamzabellouch\u002Fagent-skills --skill dynamodb-single-table-design",{"tool":40,"command":41},"bunx","bunx skills add hamzabellouch\u002Fagent-skills --skill dynamodb-single-table-design",{"tool":43,"command":44},"pnpm","pnpm dlx skills add hamzabellouch\u002Fagent-skills --skill dynamodb-single-table-design","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Fhamzabellouch\u002Fagent-skills\u002Fblob\u002Fmain\u002FProgramming\u002FBackend\u002FDatabases_and_Caching\u002Fdynamodb-single-table-design\u002FSKILL.md",true,[],[49,56,63,70,77,84],{"skillNo":50,"name":51,"nameZh":6,"description":52,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":53,"categories":54,"keywords":55,"publishedAt":19},"01M79FHH2H815A9TAP6WNKH4Q8","security-audit","Comprehensive security guidance, source code audit, vulnerability assessment, and penetration test review for codebases, APIs, microservices, CLI tools, libraries, and LLM-backed applications. Triggers on requests to audit a codebase, conduct security reviews, find vulnerabilities or flaws, pen-test source code, or when the user asks in Arabic (فحص أمني، تدقيق الكود أمنياً، مراجعة الثغرات، فحص أمان المشروع). Supports Guidance mode (focused review) and Full Audit mode (deterministic 6-phase harness).","https:\u002F\u002Fgithub.com\u002Fhamzabellouch\u002Fagent-skills\u002Fblob\u002Fmain\u002FSecurity\u002FSecurity_Audit_and_Code_Review\u002Fsecurity-audit\u002FSKILL.md",[],[],{"skillNo":57,"name":58,"nameZh":6,"description":59,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":60,"categories":61,"keywords":62,"publishedAt":19},"01M79FHBGXVBY6VQ1X7ETAZMF1","malware-analysis-reversing","Production malware analysis workflows, reverse engineering methodologies, isolated sandbox triage, static\u002Fdynamic binary analysis, memory forensics, and YARA detection rule authoring.","https:\u002F\u002Fgithub.com\u002Fhamzabellouch\u002Fagent-skills\u002Fblob\u002Fmain\u002FSecurity\u002FOffensive_Security_and_Pentesting\u002Fmalware-analysis-reversing\u002FSKILL.md",[],[],{"skillNo":64,"name":65,"nameZh":6,"description":66,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":67,"categories":68,"keywords":69,"publishedAt":19},"01M79FH6EACDR801TZCE4R8SAC","application-security-pentesting","Production Application Security (AppSec) standards, OWASP Top 10 vulnerability remediation, SAST\u002FDAST pipeline integration, secure code review, threat modeling, and defensive security posture.","https:\u002F\u002Fgithub.com\u002Fhamzabellouch\u002Fagent-skills\u002Fblob\u002Fmain\u002FSecurity\u002FOffensive_Security_and_Pentesting\u002Fapplication-security-pentesting\u002FSKILL.md",[],[],{"skillNo":71,"name":72,"nameZh":6,"description":73,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":74,"categories":75,"keywords":76,"publishedAt":19},"01M79FH0VKVT44FK923K520ZQA","oauth2-oidc-security-flows","Implement enterprise OAuth 2.1 and OpenID Connect (OIDC) authorization code flow with Proof Key for Code Exchange (PKCE), state and nonce verification, refresh token rotation, token revocation, and centralized IdP federation (Keycloak, Auth0, Okta). Trigger when building secure authentication, single sign-on (SSO), or third-party delegated authorization.","https:\u002F\u002Fgithub.com\u002Fhamzabellouch\u002Fagent-skills\u002Fblob\u002Fmain\u002FSecurity\u002FIdentity_and_Access_Management_IAM\u002Foauth2-oidc-security-flows\u002FSKILL.md",[],[],{"skillNo":78,"name":79,"nameZh":6,"description":80,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":81,"categories":82,"keywords":83,"publishedAt":19},"01M79FGVVB3R4T88XXD8FRSV5B","jwt-session-management-hardening","Harden JWT-based authentication and session lifecycles using asymmetric signing (RS256\u002FEdDSA), JWKS rotation, strict claims validation, Redis-backed sliding window sessions, revocation lists, and secure HttpOnly cookie storage. Trigger when implementing token validation, session revocation, or hardening API authentication.","https:\u002F\u002Fgithub.com\u002Fhamzabellouch\u002Fagent-skills\u002Fblob\u002Fmain\u002FSecurity\u002FIdentity_and_Access_Management_IAM\u002Fjwt-session-management-hardening\u002FSKILL.md",[],[],{"skillNo":85,"name":86,"nameZh":6,"description":87,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":88,"categories":89,"keywords":90,"publishedAt":19},"01M79FGNCPZ85CVEY0B3NE4H3B","soc2-compliance-automation","Best practices for implementing SOC 2 Type II compliance controls, continuous evidence collection, infrastructure policy-as-code, and automated security monitoring. Use when automating Trust Services Criteria (Security, Availability, Confidentiality, Processing Integrity, Privacy), audit logging, IAM least privilege, or CI\u002FCD security gates.","https:\u002F\u002Fgithub.com\u002Fhamzabellouch\u002Fagent-skills\u002Fblob\u002Fmain\u002FSecurity\u002FGovernance_Compliance_and_Legal_Tech\u002Fsoc2-compliance-automation\u002FSKILL.md",[],[]]