Back in 2018, we were building a visitor platform at Tripadvisor. We wanted to identify visitors across different websites and apps within the company, including Viator and theFork. Someone could book a restaurant in Milan through theFork and later visit Tripadvisor. We wanted to know whether these interactions came from the same person because we could do quite a bit around personalization.
This meant we needed to map cookies, device IDs, user IDs, and other identifiers to a common visitor ID. The new service would sit on the critical path of incoming requests, serving more than 20 million unique visitors a day. We had a p99 latency target of 30 milliseconds because any additional latency would slow down requests to our apps and websites. Given the geographical distribution of our subsidiaries, we also needed to replicate the visitor mappings across regions.
Naturally, one of the databases we evaluated was PostgreSQL. We used it extensively at Tripadvisor and had a database team that knew it quite well. Given the choice, I'd rather use something the company already knows how to operate.
From the get-go, we knew replication was going to be nasty. At the time, PG's native logical replication capabilities were relatively new, and we hadn't done much work around them. We wanted to serve reads and writes locally in each region, so we started looking at how we could stream changes from PG's write-ahead log across regions.
The more people looked at the problem, the more convinced we became that we could pull it off. Once we started building the proof of concept, we realized how much of a pain in the ass it was going to be. Getting changes from one database to another was hard enough. We'd also have to deal with conflicting writes and figure out how to recover from interruptions in replication. No thanks.
We ended up using Cassandra, which gave us the replication model we needed. We still had to deal with consistency at the application level, though. When a common identifier linked two visitor IDs, our merge algorithm retained the oldest one and remapped the associated identifiers. On top of that, we had another database to operate. But we had a much better understanding of what we'd be taking on.
Borrowing Confidence
In his 1995 speech at Harvard, Charlie Munger talks about oil companies acquiring fertilizer businesses. Executives weren't quite sure what to do with their capital. If Exxon was buying a fertilizer company, Mobil felt better about doing the same, and vice versa. Munger attributes this behavior to social proof, particularly under uncertainty.
When I'm evaluating a technology and find out that a few engineering organizations are using it successfully, I feel better about using it. I get much the same feeling after discussing a technical problem with engineers whose judgment I trust. Sometimes, though, those engineers are taking comfort from my judgment too. After a few conversations, we might all feel rather comfortable with something none of us has done before.
People's confidence reinforces their shared confidence, reducing their appetite to investigate unresolved unknowns.
At Tripadvisor, we could anticipate much of the cost of introducing Cassandra. We'd need people who understood it and someone to take responsibility for operating it. With PG, much of that investment had already been made. What we were less familiar with was the cost of building and operating the replication infrastructure around it. Experience with a tool can easily pass for experience with the problem.
I think familiar technologies sometimes get away with a lower burden of proof. I'm generally fond of boring technology. In other parts of the visitor platform, we used Memcached for caching and Kafka for publishing events because our folks already supported them. There was no good reason to revisit those choices. We scrutinized the database we didn't know and gave a free pass to the distributed system we were about to build around the one we did know.
Spending Money on Uncertainty
There's only so much engineering capacity to go around. After talking to a few experienced engineers, I might feel comfortable enough with the proposed architecture to allocate that capacity elsewhere. Interestingly enough, the uncertainty hasn't necessarily changed. I've just become less inclined to throw money at the problem.
When evaluating Cassandra, we investigated how much replication lag we'd see and whether it was acceptable within our consistency requirements. With PG, we never even got that far. The proof of concept made it apparent that building and maintaining the replication infrastructure was more work than we were prepared to take on. I'd have liked us to agree on how much replication lag we could tolerate and how much infrastructure we were prepared to build before evaluating either database, irrespective of how well we knew them.
If we subsequently decided that the investigation was unnecessary, I'd want to know what we'd learned since identifying the problem. Perhaps another team had already solved it under similar constraints, saving us a couple of weeks of engineering work. Having another three experienced engineers tell me they thought it was feasible wouldn't necessarily tell me anything new about the problem. Agreement has a way of feeling like evidence.
We did build the proof of concept at Tripadvisor. I still wonder how many times since then I've had enough conversations with smart people to convince myself I didn't need one.
