Hamish Dickson - LambdAle 2018
Partition
Tolerance
Consistency
Availability
CP
AP
Stay up if you start losing nodes
Same data on every node
Always get a response
up to date or error
always get a response, but could be old data
General Process:
Made up to spell "ACID"
Lets go to our favourite Algebra website
In reality you probably want to use an HyperLogLog or something
*For legal reasons not based on any Pete in this room.. maybe
Rest API
Rest API
alice likes
Likes = 721
Likes = 721
Likes = 720
This thing still needs to resolve conflicts
case class PostStats(
id: Id[Post],
likeCounter: Set[Like],
impressionCounter: Set[Impression]
)
case class Like(
postId: Id[Post],
userId: Id[User]
)
Like(Id("post-1"), Id("bob"))
PostStats(
Id("post-1"),
Counter((Id("post-1"), Id("bob"))),
Counter()
)
likes events from bob
code is going to live in our stream processor
going to cheat and only consider one post
case class PostStats(
id: Id[Post],
likeCounter: Set[Like],
impressionCounter: Set[Impression]
)
case class PostStats(
id: Id[Post],
likeCounter: Set[Like],
impressionCounter: Set[Impression]
)
and this is the same thing
we can make one for this
implicit def setSemilattice[T] = new Semilattice[Set[T]] {
def combine(s1: Set[T], s2: Set[T]): Set[T] =
s1 ++ s2
}
implicit val postStatsSemilattice = new Semilattice[PostStats] {
def combine(ps1: PostStats, ps2: PostStats): PostStats =
PostStats(
ps1.id |+| ps2.id,
ps1.likes |+| ps2.likes,
ps1.impressions |+| ps2.impressions
)
}
We have a way to do this, but it's kind of off topic
Id[Post] :: Set[Like] :: Set[Impression] :: HNil
PostStats
Id[Post] :: Set[Like] :: Set[Impression] :: HNil
but I can find one for this
wonder if I can find one for this?
Set[Like] :: Set[Impression] :: HNil
oh I found one here!
and here!
Hey compiler, find me a Semilattice for this:
PostStats
no soup for you!
Set[Impression] :: HNil
we need to define this
object AutoSemilattice {
implicit def autoSemilatticeHNil = new Semilattice[HNil] {
override def combine(x: HNil, y: HNil) = HNil
}
implicit def autoSemilatticeHCons[H, L <: HList](
implicit headSemilattice: Lazy[Semilattice[H]],
tailSemilattice: Lazy[Semilattice[L]]
) = new Semilattice[H :: L] {
override def combine(x: H :: L, y: H :: L) =
headSemilattice.value.combine(x.head, y.head) :: tailSemilattice.value.combine(x.tail, y.tail)
}
implicit def autoSemilattice[T, Repr](
implicit generic: Generic.Aux[T, Repr],
genericSemilattice: Lazy[Semilattice[Repr]]
) = new Semilattice[T] {
override def combine(x: T, y: T) =
generic.from(genericSemilattice.value.combine(generic.to(x), generic.to(y)))
}
}
Turn our type into an HList
Last bit
Find Semilattice for Head, then Tail
Or twitter me for cat pics @_mishy