Skip to content
AI-powered appsNewChat, vision, voice, generationBookings & schedulingAppointments that book themselvesShops & sellingA storefront in every pocketClient & businessRun the operation from one placeCommunities & clubsA home that is not a group chat
Health & wellnessHabits, tracking and calmGames2D, 3D and multiplayerPersonal & toolsThe tool you wish existedInternal toolsThe tool ops never had time for
See all use cases
ArcadeNewPricingSecurity
EngineThe game engine and World EditorHow it worksFrom one sentence to a live productDocsGuides for building and publishingBlogStories, guides and newsChangelogWhat shipped latelyStatusUptime of every serviceSupportGet help from the team
AI-powered appsBookings & schedulingShops & sellingClient & businessCommunities & clubsHealth & wellnessGamesPersonal & toolsInternal tools
See all use cases
ArcadeNewPricingSecurity
EngineHow it worksDocsBlogChangelogStatusSupport
Language
Blog
GuidesNovember 22, 20266 min read

How to Build a Chat App

Chat looks simple and hides four hard problems: delivering messages live, knowing who is online, tracking who has read what, and keeping strangers from abusing it.

Startbase Team
Editorial ink illustration of two tin-can telephones joined by a string across a garden fence, the knot in the string in ember orange

Key takeaways

  • The database is the source of truth: write the message, then broadcast it. Realtime is the delivery path, not the storage.
  • Presence and typing are temporary signals; never store them as rows you update every second.
  • Read receipts are one "last read message" per member per conversation, not a flag on every message.

To build a chat app, store conversations, their members and messages in a database, deliver new messages to everyone in the conversation live over a realtime connection, track each member's last read message for unread counts and read receipts, and show presence (who is online) and typing indicators as temporary signals. Add blocking, reporting and rate limits before strangers can message each other. That is the whole architecture of a solid first version, whether it is a team chat, a community chat or chat inside another product.

What kind of chat

Chat inside an existing product (buyers messaging sellers, clients messaging their coach, players in a game lobby) is the most common case and the most buildable. Standalone messengers compete with giants on network effects and on end-to-end encryption, which is a specialist field. Team and community chat sit in between: channels, mentions and threads. Decide which you are building; it decides who can start a conversation with whom, which is the most important safety rule in the app.

The data model

  • conversations: type (direct, group, channel), title for groups, created by, created date, and last message time (for sorting the inbox).
  • conversation_members: conversation id, user id, role (member, admin), joined date, muted flag, and last_read_message_id with the time it was read.
  • messages: conversation id, sender id, body, attachments, a reply-to message id, created date, edited date, deleted flag, and a client-generated id for deduplication.
  • attachments: message id, storage path, file type, size, and image dimensions.
  • blocks and reports: who blocked whom; who reported which message or user, why, and the review status.

For direct messages, make sure there is only one conversation per pair: look it up before creating a new one, with the two user ids stored in a consistent order. Two parallel "Alex and Sam" threads is a classic early bug.

Realtime delivery

The flow for sending a message:

  1. 01The sender's app shows the message immediately with a "sending" state and a client id (optimistic display).
  2. 02It inserts the message into the database. Row-level security checks that the sender is a member of the conversation and not blocked.
  3. 03Every member currently viewing the conversation receives the new row through a realtime subscription to that conversation and appends it, skipping any message whose client id it already shows.
  4. 04The sender's copy flips from "sending" to "sent" when the insert succeeds, or shows Retry if it fails.
  5. 05Members not in the app are notified by another path (email digest now, push notifications in a native build later).

Startbase Cloud runs on Supabase, and its realtime channels carry live updates like these; the Multiplayer docs note that live sync for lobbies, presence and live boards runs on your backend's realtime channels. The database remains the record, so when someone reconnects after a dropped connection, the app loads messages newer than the last one it has, and nothing is missed.

Load history in pages: the newest 30 messages on open, older ones as the user scrolls up, keeping the scroll position steady as they load. Order by created time with the id as a tiebreaker.

Presence and typing indicators

Presence (green dot) and typing ("Sam is typing") change constantly and matter only right now. Send them over the realtime channel's presence or broadcast features, not as database rows: writing a row every keystroke would swamp the database for no lasting value. Typing signals should be throttled (send at most every two or three seconds while typing) and expire on their own after a few seconds of silence. For "last seen" on a profile, write a timestamp to the database occasionally, such as when the app is closed, not continuously.

Tip

Make presence optional. Some people do not want others to see when they are online, and a privacy setting that hides it costs almost nothing to build.

Unread counts and read receipts

Do not store a read flag per message per person; in a group of 50 that is 50 writes per message. Instead, each membership row holds the last message that member has read. When a member views the conversation, update it to the newest visible message (debounced, not on every scroll). Then:

  • Unread count for a conversation is the number of messages newer than my last read message (not counting my own).
  • Read receipts in a direct chat: show "Read" under my latest message if the other person's last read message is the same or newer.
  • In groups, "Seen by 4" under a message counts members whose last read message is at or after it; tap to see who.

Broadcast read updates on the realtime channel so the sender's screen updates without a refresh.

Safety, abuse and attachments

  • Who can message whom: in a marketplace, only parties to a listing; in a community, only members; for direct messages between strangers, consider message requests that the recipient accepts first.
  • Block stops all messages both ways and hides the conversation; enforce it in the database rules, not only the interface.
  • Report on any message, with the surrounding messages captured for review.
  • Rate limits: a few messages per second per user and a cap on new conversations per day stop spam scripts.
  • Attachments in a private storage bucket, readable only by conversation members through signed links. Limit file types and sizes. In Startbase Cloud, new buckets are private and signed links last an hour (Storage).
  • Deletion: "delete for everyone" replaces the body with "message deleted" and removes attachments; keep a record only if your policy says so.

Notifications for people who are away

Email is a solid first channel: a scheduled job every 15 minutes or so finds members with unread messages older than a few minutes who have not been active, and sends one digest per person ("3 new messages from Sam"), never one email per message. Startbase Cloud jobs run on pg_cron, and emails go through the platform sender (a daily per-project limit applies) or your own domain; see Emails. Mobile push notifications need a native build of your own; an Expo app runs on your phone through Expo Go during development, and App Store and Play Store builds are not available from Startbase right now.

What to leave out of version one

  • End-to-end encryption. It is a specialist architecture; do not claim it unless you implement a vetted protocol.
  • Voice and video calls.
  • Threads, reactions and rich message formatting beyond links and line breaks. Reactions are a good second feature.
  • Message search across all conversations.
  • Bots and integrations.

A brief you can paste

Add chat to my tutoring marketplace. Students can message a tutor only after booking; tutors can reply but not start conversations with strangers. Conversations are direct (one per student and tutor pair) or group (a tutor and up to 8 students in a class). Messages have body, optional reply-to, image or PDF attachments up to 10 MB in a private bucket with signed links, edited and deleted states. Show messages instantly with a sending state and a client id, insert into the database, and deliver to other members over a realtime subscription, deduplicating by client id. Load the newest 30 messages and older ones on scroll up. Online dots and typing indicators over realtime presence and broadcast, not database rows; a setting hides my online status. Each membership stores last read message; show unread counts in the inbox, Read under my last message in direct chats and Seen by N in groups. Block and Report on every conversation, enforced in the database. Limit 5 messages per second. A job every 15 minutes emails a digest to members with unread messages older than 10 minutes who are inactive.

Test with two browsers side by side, then turn off the network in one, send three messages from the other, and reconnect. Everything should arrive in order with no duplicates. For the rest of a two-sided product around chat, see the marketplace guide, and for live features beyond messaging, how to build a multiplayer game. If chat is the whole product, what a social media app costs gives realistic budget ranges.

Frequently asked questions

How do chat apps send messages in real time?

The message is saved to the database and then pushed to everyone viewing the conversation over a realtime connection such as WebSockets. The app shows it immediately as sending, and reconnecting clients fetch anything they missed from the database.

How do read receipts work?

Each member of a conversation has a "last read message" pointer that updates when they view it. A message is read by someone if their pointer is at or after it, and unread counts are messages after your own pointer.

How do typing indicators work?

The app sends a short-lived "typing" signal over the realtime channel, throttled to every few seconds, and the indicator disappears if no new signal arrives. It is not stored in the database.

Do I need end-to-end encryption for my chat app?

For chat inside a marketplace, community or business tool, encryption in transit and at rest with strict access rules is the usual standard. End-to-end encryption is a specialist design, needed mainly for private messengers, and should only be claimed if properly implemented.

On this page

  • What kind of chat
  • The data model
  • Realtime delivery
  • Presence and typing indicators
  • Unread counts and read receipts
  • Safety, abuse and attachments
  • Notifications for people who are away
  • What to leave out of version one
  • A brief you can paste

Keep reading

More in Guides
Editorial ink illustration of a kitchen scale with an apple on its pan beside a notepad and a spoon, the apple in ember orange
GuidesNovember 22, 2026

How to Build a Calorie Tracker App

Calorie tracking fails when logging is slow or the numbers are wrong. Get reliable food data, make repeat meals one tap, and be honest that every number is an estimate.

6 min read
Editorial ink illustration of two paper lanterns drifting toward each other over a small bridge, the glow of one lantern in ember orange
GuidesNovember 22, 2026

How to Build a Dating App

A dating app is a matching engine wrapped in a trust problem. Here is the data model, the screens and the safety work that has to ship on day one.

6 min read

Read less. Ship more.

Everything in this post is one prompt away. Describe your app and watch it build.

Start building

Apps, games, backends and publishing from one conversation.

Product

  • Features
  • Use cases
  • Pricing
  • Changelog

Resources

  • Blog
  • Docs
  • Support
  • Status
  • Security

Contact

  • w@startbase.ai
  • X / Twitter
  • LinkedIn
  • Instagram

Legal

  • Terms
  • Privacy

© 2026 Startbase. All rights reserved.