Case-insensitive queries in DynamoDB
Codemia Knowledge Hub ·
DynamoDB has no case-insensitive query option: comparisons are case-sensitive, so a query for partition key UserId "smith" will not match an item stored as "Smith". To match regardless of case, store a normalized (for example lowercase) version of the value and normalize the search term the same way before querying.
Normalize on write and on read
The most common strategy is to transform both the stored data and the query input to the same format, such as lowercase, using string functions in the application code that talks to DynamoDB. For example, if you store and query users by a primary key username, convert the username to lowercase before writing the record:
During a query, transform the search term to lowercase too, so it matches what was stored:
Keep a lowercase copy in a global secondary index
Another approach uses a Global Secondary Index (GSI) to hold a case-insensitive duplicate of the key. When a record is created, the key attribute is stored both in its original form and as its lowercase equivalent, and the GSI is built on the lowercase value so queries can use it:
Backfill with DynamoDB Streams and AWS Lambda
For existing implementations that were not normalized from the start, a Lambda function attached to DynamoDB Streams can normalize automatically. It listens for changes in the table and writes the lowercase value to the corresponding field:
Trade-offs of each approach
Case-insensitive matching in DynamoDB comes from how you shape the data rather than from a database feature, and each technique has costs:
- Storage overhead: duplicating data for normalization increases storage.
- Consistency: asynchronous steps like streams can add latency and consistency concerns.
- Complexity: GSIs and Lambda functions make the system more complex.
| Strategy | Description | Pros | Cons |
| Data Normalization | Convert both stored and query data to a consistent format (e.g., lowercase). | Simple to implement in app layer | Requires consistent codebase adherence |
| Global Secondary Index (GSI) | Use a GSI to store and query normalized data. | Efficient querying | Additional costs for maintenance |
| DynamoDB Streams and AWS Lambda | Normalize incoming data using automation. | Automated handling | Potential latency and complexity |
Related reading
- Catching boto3 ClientError subclass
- Celery connection drop with AWS ELB and RabbitMQ
- Change key pair for ec2 instance
- Change platform on Elastic Beanstalk from PHP to Node.js
- Case insensitive string compare in LINQ-to-SQL
- Cassandra - read during update consistency
- Cassandra batch query vs single insert performance
- Cassandra control SSTable size
System design interview problems on this topic
- Design Dropbox: solution and walkthrough
- Design a Global Content Distribution Network: solution and walkthrough
- Design a Serverless Architecture Framework: solution and walkthrough
- Design Youtube or Netflix: solution and walkthrough

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseSystem Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.