Telavian
Telavian

Reputation: 3832

Service architecture using service fabric

I am designing a stateless service which essentially processes a stream of information and then based on conditions sends emails. I want to host this in service fabric, with more than one active in case of failure, however how do I limit the email to be sent from only the "primary".

Is active/active only valid for stateful services which are partitioned? If the services have to be active/passive then how does the service know when it is now the active one?

Upvotes: 1

Views: 225

Answers (3)

anderso
anderso

Reputation: 981

Another option is to have a pool of stateless workers that process your data stream, and then whenever it wants to send an email, it'll notify another service (through ServiceRemoting/Rest/ServiceBus/other communication channel) and this service will handle the actual sending of emails.

If this email sending service is stateful, it can then handle duplicates if that's one concern you have.

Upvotes: 0

duongthaiha
duongthaiha

Reputation: 855

I will go with Stateful service for couple reasons:

  • You only want one "primary" to handle the email.
  • You want a backup/replica in case the primary went down. This is default by stateful service
  • Its difficult with multiple instance of stateless service. When you have stream of information that handled by multiple instance. What if the condition for sending email is not happening on "primary" node. You then have to a separate mechanism to transfer that data/state to the "primary" node.

Upvotes: 0

LoekD
LoekD

Reputation: 11470

There's no built-in mechanism for leader election (that you can use) inside SF. You could use a blob lease. The leader will be the one who acquires the lease, and needs to refresh it while it's 'alive'. If it crashes, it will lose the lease and another instance can get it. This does introduce an external dependency, lowering the overall availability % of your system.

You could also create a Stateful service that does something similar.

Upvotes: 2

Related Questions