Time Series Feature Design: Replication
Join the DZone community and get the full member experience.Join For Free
armed with the knowledge about replication strategies from my previous post , we can now consider this in the context of the time series database.
we actually have two distinct pieces of data that we track. we have the actual time data, the timestamp and value that we keep track of, and we have the series information (tags, mostly). we can consider using log shipping here, and that would give us a great way to get a read replica. but the question is why we would want to do that. it is nice to get a replica, but that replica would have to be read only. is that useful? it could take over, if the master is down, but that would mean that the master would have to stay down (or converted to a slave). and divergent writes are a problem.
while attractive as a cheap way to handle replication, i don’t like this very much.
so that leaves us with using a multi write partners situation. in this case, we can allow the two servers to operate in tandem. we need to have some way to resolve conflicts, and this is where things gets a bit messy.
for series data, it is trivial to just use some form of last write wins. this assumes a synchronized clock between the servers, but we’ll leave that requirement for now.
the problem is with the actual time data. conceptually, we intend to store the information like this:
the problem is how do you detect conflicts. and are they really even possible. let us assume that we want to update a particular value at time t on both servers. server a replicates to server b, and now we need to decide how to deal with it. ignore the value? overwrite the value?
the important thing is that we need some predictable way to handle this that will end up with all the nodes in the cluster having the same agreed upon value. the simplest scenario, assuming a clock sync, is to use the write timestamp. but that would require us to keep the write time stamp. currently we can use just 16 bytes for each time record. but recording the write timestamp will increase our usage to 24 bytes. that is a 50% increase just to handle conflicts. i don’t want to pay that.
the good thing about time series data is that a single value isn’t that important, and the likelihood that they will be changed it relatively small. we can just decide to say: we’ll choose a value, for example, we will choose the maximum value for that time, and be done with it. that has its own set of problems, but we’ll deal with that in a bit. we need to discuss how we deal with replication in general, first.
let us imagine that we have 3 servers:
- server a replicates to b
- server b replicates to c
- server c replicates to a
we have concurrent writes to the same time value on both server a and b. for the purpose of the discussion, let us assume that we have a way to resolve the conflict.
server a notifies server b about the change, but server b already have a different value for that. conflict resolution is run, and we have a new value .that value need to be replicated down stream. it goes to server c, who then replicate it to server a, who then replicates it to server b? ad infinitum?
i intentionally chose this example, but the same thing can happen with just two servers replicating to one another (master/master). and the problem here is that in order to be able to actually track this properly, we are going to need to keep a lot of metadata around, per value . while i can sort of accept the need to keep the write time (thus requiring 50% more space per value), the idea of holding many times more metadata for replication purposes than the actual data we want to replicate seems… silly at best.
log shipping replication it is, at least until someone can come up with a better way to resolve the issues above.
Published at DZone with permission of Oren Eini, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.