I want to design a solution for sending different kinds of e-mails to several providers. The general overview.
I have several upstream providers Sendgrid, Zoho, Mailgun and etc. They will be used to send e-mails and etc. For example:
- E-mail for Register new user
- E-mail for Remove user
- E-mail for Space Quota limit
(in general around 6 types of e-mails)
Every type of e-mail should be generated into Producers, converted into Serialized Java Object and Send to the appropriate Kafka Consumer integrated with the Upstream provider.
The questions is how to design Kafka for maximum performance and scalability?
1-st solution so far that I can think if is to have topic for every type of e-mail message and every gateway(6x4 = 24 topics). In the future I'm expecting to add more types of messages and gateways. Maybe it will reach 600 topics. This will make a lot Java source code for maintenance and a lot of topics to manage. Another downside will be that Kafka logs will be huge.
2-nd solution will be to use 1 topic for each consumer(integration gateway). But in this case how I can send every type different serialized Java object based on the type of message that I want to send?
Is there some better way to design this setup so that it allow me to scale it much more easy and make it very robust for future integrations?
You can see here how I send message between consumers and producers: org.apache.kafka.common.KafkaException: class SaleRequestFactory is not an instance of org.apache.kafka.common.serialization.Serializer
EDIT:
- Order matters because the communication will be asyncronius. Producers will wait for returned messages for status
- It's not important to keep the data of each gateway on a different topic
- What kind of isolation do you want? I want ot isolate the messages/topics completely from each other in order to prevent mistakes in future when I need to add more gateways or types of messages
is it important to you to keep the data of each gateway on a different topic? - no, I just want ot isolate hte data.
If you would go with a single topic per gateway, do you care about the overhead it will make on the client-side? - read unnecessary messages, write more logic, hybrid serializer, etc
I have no idea here. My main consern is to make the system easy to extent with new features.