feat: multi-keys design for GSI#12
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Changes
This PR implements a complete refactoring to DynamoDB Single-Table Design using the new Multi-Key (Composite Keys) GSI feature announced by AWS.
AWS Multi-Key GSI Blog: https://aws.amazon.com/blogs/database/multi-key-support-for-global-secondary-index-in-amazon-dynamodb/
Database Architecture
Single-Table Design with Multi-Entity Support
Table:
glad-entitiesentity_id(Partition Key only)Entity Key Patterns
Global Secondary Indexes (GSI)
1. ByUser - User Profile + Skills
2. ByEntityType - Entity Listing
3. BySkillID - Denormalization Sync
4. SkillsByLevel - Skill Search (Multi-Key Composite)
5. SkillsByCategory - Category Browsing
Data Model
3-Entity Model
1. User (Profile)
2. Skill (Master Catalog)
3. UserSkill (User's Skills with Denormalized Data)
Key Features Implemented
1. Master Skills Catalog
skill_idand mutable display metadataskill_idSkillNameandCategorycopied to UserSkills for query performance2. Repository Layer Refactoring
New Repository Interfaces:
UserRepository- User CRUD operationsSkillRepository- UserSkill CRUD operationsMasterSkillRepository- Master skill catalog managementRepository- Unified interface combining all threeImplementations:
DynamoDBRepository- Production implementation using AWS SDKMockRepository- In-memory implementation for local development3. Centralized Key Generation
File:
cmd/app/internal/models/keys.goSingle source of truth for all entity key construction:
4. Master Skill Lookup Service
Before:
After:
5. Comprehensive Validation
Skill ID Validation:
python,aws-lambda,react-jsCategory Validation:
Skill Name Validation:
Implementation Details
Files Created
Database Layer:
cmd/app/internal/database/constants.go- Table and GSI name constantscmd/app/internal/database/entity_keys.go- Entity key constants (deprecated, moved to models)cmd/app/internal/database/master_skill_repository.go- Master skill operationscmd/app/internal/database/user_skill_repository.go- User skill operationscmd/app/internal/database/user_repository.go- User operations (extracted from monolithic file)cmd/app/internal/database/skill_repository.go- Skill repository interfaceModels:
cmd/app/internal/models/keys.go- Centralized entity key builderscmd/app/internal/models/skill.go- Master skill domain model with validationcmd/app/internal/models/user_skill.go- User skill domain modelServices:
cmd/app/internal/service/master_skill_service.go- Master skill business logicHandlers:
cmd/app/internal/handler/master_skill_handler.go- Master skill API endpointsDocumentation:
cmd/app/testdata/dynamo-db-multi-keys-queries.md- Query examples and test datadocs/api-testing/api-test.http- API testing examplesdocs/api-testing/http-client.env.json- Environment configurationFiles Modified
Core Application:
cmd/app/main.go- Updated service initialization with both repositoriescmd/app/integration_test.go- Updated test setup for new repository structureDatabase Layer:
cmd/app/internal/database/dynamodb.go- Refactored to interface implementationcmd/app/internal/database/factory.go- Repository factory patterncmd/app/internal/database/mock.go- Fixed key generation, added master skills supportcmd/app/internal/database/mock_test.go- Updated tests for skillID parameterModels:
cmd/app/internal/models/user.go- Updated to use centralized key builderscmd/app/internal/models/user_skill.go- Added denormalization fieldsServices:
cmd/app/internal/service/skill_service.go- Implemented master skill lookupHandlers:
cmd/app/internal/handler/user_handler.go- Updated for new repository interfacescmd/app/internal/handler/user_handler_test.go- Test updatesInfrastructure:
deployments/app/cdk.go- Complete GSI definitions with multi-key supportcmd/app/internal/dto/dto.go- Added DTOs for master skillsDocumentation:
README.md- Added Multi-Key GSI referenceFiles Deleted (Outdated Documentation)
docs/README-DYNAMODB-DESIGN.mddocs/dynamodb-quick-reference.mddocs/dynamodb-single-table-design-plan.mddocs/entity-addition-protocol.mdTesting
Test Files Updated
cmd/app/internal/database/mock_test.go- Updated to use skillID parametercmd/app/integration_test.go- Updated repository initializationQuery Performance Examples
Find Expert Python Developers with 5+ Years
Get User Profile + All Skills (Single Query)
List All Master Skills in Programming Category
Design Patterns Applied
🔗 References