Original post

Lately, I have been reading on RAFT and hashicorp implementation of it. I was checking out this example implementation: https://github.com/otoolep/hraftd/blob/master/store/store.go#L99

In this case, raft.NewRaft takes an object implementing FSM interface as the second argument.

In the above example, it seems the author has typecasted the store object to fsm pointer which is nothing but:

type fsm store

After that the function signature is like: https://github.com/otoolep/hraftd/blob/master/store/store.go#L206 instead of something like:

function (s *Store) Apply ...

The code would have just worked too if we did:

NewRaft(.., s, ...)

instead of


Since this was the first time seeing such a pattern, I wrote a sample playground and that seems to behave the exact way.


I am a bit confused of this pattern. What exactly is this pattern called and what are the benefits?