A database choice that starts with a search problem
Imagine you're building a messaging application.
Users send thousands of messages every second. Over time, the application stores billions of messages. And users expect something that sounds simple:
"Show me all the messages containing the word 'football'."
At first, this looks like a straightforward database query.
If you're familiar with PostgreSQL, you might start with a table like this:
CREATE TABLE messages ( id BIGSERIAL PRIMARY KEY , user_id BIGINT NOT NULL , message_text TEXT NOT NULL , created_at TIMESTAMP NOT NULL );
Enter fullscreen mode
Exit fullscreen mode
To search for messages containing a particular word, PostgreSQL provides full-text search.
For example:
SELECT id , message_text , created_at FROM messages WHERE to_tsvector ( 'english' , message_text ) @@ plainto_tsquery ( 'english' , 'football' );
Enter fullscreen mode
Exit fullscreen mode
You can improve this with a GIN index:
CREATE INDEX messages_search_idx ON messages…