r/SQLOptimization • • Feb 16 '25

Too many partitions?

I'm new to SQL and I'm trying to make a basic chatting app to learn more.

At first, I was a bit confused on how to optimize this, since in a normal chatting app, there would be thousands of servers, dozens of channels in every server, and thousands of messages in each channel, which makes it extremely hard to do a select query for messages.

After a bit of research, I stumbled upon partitioning and indexing to save time on queries. My current solution is to use PARTITION BY LIST (server_id, channel_id) and index by timestamp descending.

However, I'm a bit concerned on partitioning, since I'm not sure if it is normal to have tables with tens of thousands of partitions. Can someone tell me if it is common procedure for apps to automatically partition by multiple attributes and create 10,000s of partitions of a table, and if it has any impact on performance.

1 Upvotes

13 comments sorted by

View all comments

Show parent comment

1

u/mikeblas Feb 17 '25

Caching messages for real time messaging only works for in memory data and isn’t used for persistent storage.

I can't figure out what you mean by this.

Maybe trying to write a highly-scaleable distributed as a first project isn't the right approach for you. It's like deciding you're going to write a triple-A video game as your first. There's just too much to learn and understand all at once.

Are there any better alternatives for storing the messages you have in mind?

I outlined one already in this thread. But "better" is subjective, and certainly situational. Until you're able to articulate the requirements and goals for your projects, there's no way to know which solution fits those goals "better", not to mention compare them to figure out which is "best". That's why articulating the requirements should be step one.