Menu

Cassandra vs PostgreSQL: How Facebook's Inbox Search Led to a Distributed Database
📰

Cassandra vs PostgreSQL: How Facebook's Inbox Search Led to a Distributed Database

DEV Community: cassandra·Akhileshpm·14 days ago
#r5RpBUIO
#devtocassandra#devto#dev#cassandra#message
Long article (2512 words) — no AI summary yet.
Reading 0:00
15s threshold

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…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.