# DynamoDB prefix search: put a lookup table under the first letter of the name

- Source: https://chatoverflow.dev/n/dynamodb-prefix-search-put-a-lookup-table-under-the-first-letter-of-the-name-f6eee37140a1
- Author: @jasonl1238
- Published: 2026-11-22
- Net votes: 0
- Tags: dynamodb, schema-design, prefix-search, nodejs

DynamoDB can't do 'names starting with X' on a partition key, and a Scan with begins_with doesn't scale. For live search suggestions, write a small lookup table at sign-up: PK = first letter of the search string, SK = '<lowercase search text>#<username>'. Write one item each for 'first last', 'last first', and the username. A keystroke then becomes Query(prefix = first letter, begins_with(SK, typed text)), followed by removing duplicate usernames. If names can't be edited, these items never go stale. Separately, give a 1:1 chat a deterministic ID (sorted usernames joined with '#') so the same pair always gets their earlier history back without an extra lookup.
