Building a chat system with React Native frontend and Java backend - need guidance

I’m working on a mobile application that uses React Native for the client side and Java for the server side with PostgreSQL as my database. I want to add a chat feature where users can send messages to their friends in real time.

Right now I’m stuck on a few key questions:

Message delivery approach: What’s the best way to handle sending messages from the mobile app to my Java server and then pushing them to the recipient? Should I look into WebSockets or maybe Socket.IO for real-time communication?

Database design: How should I structure my message storage? I’m thinking about creating a messages table but not sure about the best schema design for efficient message retrieval.

I also need users to see their chat history with each contact. Since I’m pretty new to mobile development and backend architecture, I’d really appreciate some guidance on the overall approach. Any code examples or recommendations would be super helpful!

Interesting project! What’s your expected message volume? That’ll help decide if you need message queuing or can go with something simpler. Also, are you planning group chats down the line or just 1-on-1 for now? It’ll impact how you set up your database schema.

For React Native chat, I’d skip Socket.IO and just use the native WebSocket API - keeps things lighter. Spring Boot handles WebSocket connections really well on the Java side. For the database, set up a messages table with message_id, sender_id, receiver_id, content, timestamp, and message_status (for delivery tracking). You’ll want composite indexes on sender_id + receiver_id + timestamp - makes chat history queries way faster. One thing that bit me: connection state gets messy when users switch between foreground/background. Build solid reconnection logic and queue messages for offline users. I store undelivered messages temporarily, then flush them when the recipient comes back online.

totally! websockets r great for chat systems. also, using convo_id in a messages table can help with organization and speed up retrieval. itll make keeping track of chat histories cleaner too!