/work/smata · chat & messaging

Four conversation types, one chat.

SMATA's strata management platform had grown four separate places for people to talk about work. As part of the core Rails team, I moved those conversations onto one chat model and owned the data migration that carried the existing comments across.

Product
SMATA, strata management SaaS
Scale
500,000+ users on the platform
My role
Conversion work and the data migration, end to end
Stack
Rails · PostgreSQL · Elasticsearch · RSpec

/problem

What was going wrong.

  • Conversations about jobs, conversations with contractors, noticeboards and vote options each stored comments separately, each with its own unread logic.
  • Managers and contractors saw unread indicators and counts that didn't agree, so messages were easy to miss.
  • Any change to messaging had to be made, tested and supported in four places.

/my-part

What I did.

01

Moved conversations onto chat rooms

Converted manager and contractor conversations and job conversations to the new chat-room model, with migrations giving each job and contractor its base chat room.

02

Brought the rest across

Moved noticeboard and vote-option comments into chat messages, so every conversation uses the same model.

03

Built the data migration

Designed and wrote the comment-to-message migration service: batched, idempotent, driven by a cutoff date, keeping each user's read state, and able to carry on if search indexing failed for a record.

04

Cleaned up

Added a task to catch any stragglers and removed the old comment counts from unread totals, so there is one source of truth.

/approach

Built to be re-run safely.

Migrating live conversations is risky: a half-finished run can duplicate or lose messages. The migration works in batches of 500 and looks for an existing message before creating one, so a re-run doesn't duplicate what's already there. Read state moves with each message, so nobody's inbox lights up with old comments, and a search-indexing hiccup on one record doesn't stop the run. What I'd add next time: an automated test that runs the migration twice. It was designed to be safe to re-run, but a test is what proves it.

comment_to_message_migration (simplified)
message = chat_room.messages.find_or_initialize_by(
  body: comment.body,
  sender_id: sender_id,
  created_at: comment.created_at
)
message.save! if message.new_record?  # safe to re-run

/result

What changed.

4 → 1conversation types merged into one chat model
42commits of my own over about 14 months
500records per batch, so a failure never takes the whole run down
  • Job, contractor, noticeboard and voting conversations now share one chat model.
  • Unread counts come from one place, so indicators agree across the product.
  • The migration is designed to be re-run safely: batched, and it checks for each message before creating it.
  • Future messaging features are built once, not four times.

Credit where it's due. The new chat-room foundation was built by teammates in SMATA's core Rails team. My part was converting the existing conversations onto it and the comment-to-message data migration, which I designed and wrote end to end.

Got a Rails app with problems like these?

Untangling a system that has grown in several directions is rescue work. Tell me what's happening, or book a call.

/more-work

Start a project