Search code examples
publish-subscribeably-realtime

How to set up an e-commerce messaging solution using ably.io


I have an e-commerce website and I want to implement a messaging solution between my clients, using ably.io. I am new to ably.io and also to pub/sub message pattern and need some advice to put me on the right track.

Let’s say I have 75,000 users on my website. Users can create an advertisement... if anyone is interested in the advertisement they should be able to message the advertiser.

This is the solution that comes to my mind after reading ably's documentation:

Since I have 75,000 users, I create 75,000 channels, 1 channel per user.

An user named Brian creates an advertisement on the website. Brian subscribes to BrianChannel to receive all messages on his own channel. Now Amy and Tom have seen Brian's advertisement and want to contact him, they publish a message on BrianChannel and Brian would receive the messages.

I am not sure if the above solution is the right approach?

If the above solution is the right way, I have 2 further questions:

  1. Let's Brian uses JavaScript to subscribe to BrianChannel. Now Brian is obviously not online 24/7 - how should I handle his messages while he is offline?

  2. I have 75,000 users registered on my website. At any point of time 5,000 users are online. Out of these 5000 users online, 20 users are actually messaging each other. Using my solution above, I should have 5,000 active channels for all the online users... Is there a way to reduce the number of active channels? Perhaps by periodically polling the channels?


Solution

  • This is Srushtika, Dev Advocate at Ably.

    • Your approach is correct and is in-fact the most commonly implemented one. i.e, each of your 75,000 users will have their own channels to which only they will be subscribed to. Any other client who wishes to send them a message, will attach to 'their' channel and publish messages to it. Since all users are always subscribed to their own channels, they will be able to receive any messages intended for them.

    • If any of your subscriber clients are not online at the time a message is to be sent to them, Ably's Realtime platform will, by default, retain it for 2min after which, if the subscriber client is still offline, the messages will be discarded. However, using the Persisted History feature, you can increase the time for which messages are retained to 24-72hrs.

    • Unfortunately, as of now, Ably doesn't offer a mechanism to detach from channels with no activity while the client is still online. But, this feature is coming soon. Keep an eye on our Engineering blog where we post all such updates.

    Hope that answers your question.