First you have to ask yourself why is the second phase of your project to use a consensus algorithm? Does the project require strong consistency? Have you considered alternative replication protocols (gossip, primary-backup, etc)
Regardless of which Raft implementation you use, the way most implementations model state within the system is as a state machine. Changes to the state of the system must go through the Raft protocol to the leader and be replicated to followers, and queries on the state of the system must go through the protocol as well if you want to preserve consistency/fault tolerance guarantees.
If you want to embed Copycat within a server, just use a LocalTransport
Which allows you to communicate with an in-process server. The CopycatServer
doesn't have to run on a remote machine. It's perfectly realistic and rational to embed the Copycat client and server within your Thrift server. Within your Thrift server, create a CopycatServer
that contains a state machine that can represent changes to the state of your system, and a CopycatClient
that uses a LocalTransport
to communicate with the local server.
You might also consider looking at using Atomix in which AtomixReplica
handles this local client/server embedding pattern for you. It also includes a plethora of example state machines and client APIs.
But as I said, regardless of whether you use Copycat/Atomix or another Raft implementation, you'll still have to model state changes in the same way. Each change to the state of the system must be submitted to a Raft leader where it's logged and replicated to followers and applied to a state machine. The state machine replication model is well suited to stateful systems. An alternative for systems that are storing large amounts of state or need to store state in an external database is persistent state machines. I find that this is what many users are looking for in Raft. But you have to be careful with how persistent state machines are implementated within a Raft cluster, otherwise you'll risk duplicating writes.
Still, you should first determine whether a complex protocol like Raft is necessary for the problem you're trying to solve. First answer what that problem is, and what it requires from a replication protocol. Do you need partition tolerance? Do you need strong consistency? Do you need high availability? Do throughput requirements preclude using a leader-based protocol? Why not just write to any external database that's replicated?
I am the author of Copycat and Atomix. Feel free to join us on chat when you answer some of those questions and determine whether this is indeed the right direction to go.