
Preamble
I would say I’m a pretty curious person. As a kid, I was the type to ask "why?" over and over until I got an answer I was happy with. Unfortunately, that strategy tends to get you smacked as an adult. Nevertheless, this has not deterred my curiosity, especially when it comes to software. At Palantir, I had the opportunity to work on many different types of problems. This came as both a blessing and a curse. On one hand, it was nice to gain exposure to unfamiliar industries and the challenges that came with them. On the other, constantly tackling different problems meant not having the opportunity to sit down and dive deeply into any single one. This was the dilemma I was faced with. Do I want to optimize my curiosity for breadth or depth?
The tipping point of my decision came when my Palantir mentor and I encountered a peculiar bug together (to get the message across without spilling company secrets, I will make up a scenario). One of the jobs in the pipeline kept failing and the error messages were obscure. So, we pulled up Grafana to dive into the logs and visualizations. After a few minutes, my mentor pointed out a sharp drop in throughput that coincided with a cluster outage earlier that day. After further digging, he notes that a compute cluster running part of the job had gone down. When the cluster failed, too many replicas went down at once and became unavailable. The job kept retrying, but without access to its persisted state, it could no longer recover and eventually aborted.
What struck me was not only how deep his systems knowledge was, but also the speed at which he came to those conclusions. After asking him about this, he told me that prior to becoming forward-deployed, he spent a few years as a traditional software engineer. It was here that he developed his skills in software infrastructure. Although he tried to reassure me that technical depth to that level is not necessary for a forward-deployed engineer, I still felt quite dull. I disliked not knowing what went on behind the scenes. To me, I felt incomplete as a software engineer if I didn’t understand how to debug at a lower level.
That feeling of inadequacy stuck with me for the next few months. I decided then that I wanted my next internship to be in infrastructure. I wanted to understand how companies actually built the systems underneath their software products. Naturally, Databricks caught my eye. Primarily considered a data and AI company, Databricks provides the software layer to manage and orchestrate cloud infrastructure. And after a few months of interviews, I was going to get to see that layer for myself.

The work
I was pretty excited for my internship at Databricks. I had the chance to meet with my manager prior to my start date and got a sneak peek at the work I would be doing. He told me I was on a core infrastructure team with a specific focus on caching infrastructure. I didn’t know much about caching at the time; I’d heard of Redis and the concept of key-value stores, but I’d never dug deeper than that. He told me the caching team builds caches for two types of services: stateless and stateful. Stateless services are services which do not maintain any state in memory after an operation completes. Think of an API that performs a simple math operation on two numbers. No in-memory state is kept after handling this operation, and any pod can handle any of these requests. On the other hand, stateful services cache state in memory. As a contrived example, think of a service that tracks a per-user counter. On each request, the service has to look up the user’s ID and increment their count. You can imagine the user ID and count stored in an in-memory map living on a particular pod. This means the map persists across requests, but it also means that every request for the same user ID must land on the same pod.
This introductory conversation with my manager really set the tone for me. For the first time, I felt like my computer science degree was being put to use. Topics like distributed systems and concurrency rang bells from courses I'd taken. For better or worse, Databricks gave off a more research-y vibe, and the caching work reminded me of the kinds of assignments I used to do at university.
And just like in university, my colleagues on the caching team gave me some intense imposter syndrome. Turns out my research hunch was right, since nearly everyone on the team has a Master's, with a few PhDs scattered in as well. On top of that, most of them have over a decade of industry experience, with some of them starting their full-time careers before I was even born. A majority of my team actually came from Google, specifically the team under Atul Adya. I bring him up because Atul is the engineer who shaped a lot of the philosophies our caching team has now adopted. Likely established during his time at Google, Atul has been very vocal about his belief in stateful services. And considering he also brought over a small army of ex-Googlers, I’m guessing he was a pretty great leader there, too. I spent some time reading a few of Atul’s research papers, hoping to understand how this team thought and worked.
Interlude
I do think part of the reason I was able to work so hard during the past 16 weeks was the absolutely poopy weather. This internship took place during the winter in the Greater Seattle Area. Seattle's only about a 2.5-hour drive from Vancouver, and as a Canadian, I’ve always heard Vancouver gets a lot of rain. Seattle, unfortunately, gets a lot of rain too. And rain, unfortunately, comes from clouds. Clouds, unfortunately, block the sun. So since it rained nearly every day, I basically never saw the sun. With very little motivation to go outside, I spent most days staring at my work laptop a little harder, hoping the sun would eventually feel guilty enough to come out. Here’s a picture of the Space Needle on my first day. Foggy as ever. The CN Tower looks way better.

Caching team
A good chunk of my time working was spent drawing on the whiteboard. The caching team has built services to work with both stateless and stateful architectures. It took me some time to understand why each service is built in its own particular way. Although I can’t talk about the services themselves, I want to speak more on the overarching stateless and stateful paradigms.
Stateless services
Traditionally, stateless services were the way to go. Even in college, keeping states tied to the storage system was how we always defined our application servers and databases. When I worked with web applications in previous internships, it was a rule of thumb to have any application server be able to handle any request. One big benefit of doing so is availability: if one server crashes, it does not affect any other server. Another benefit is scalability: adding/removing servers is easy when state is disregarded.
There are countless articles discussing the benefits of statelessness. However, the main argument these articles make against stateful services is the complexity of maintaining multiple servers with cached application state. What happens when a server goes down? How can we reroute requests to target the other servers while still load balancing properly? How can we add/remove servers effectively? The answer that many have come to is a sharding system. However, for years, engineers wrote off this solution since static sharding schemes can’t react well enough to stressed systems. For example, imagine a hash-based sharding system that routes requests to specific pods. If a particular pod gets too hot, the hash function will keep routing requests to it, regardless of how loaded the pod is or whether other pods have spare capacity. That’s the nature of static sharding. The usual workaround is to overprovision and intervene manually, both of which get expensive fast.
However, stateless services are not perfect. Since state is stored outside of its application servers, a remote cache is typically introduced to enable faster retrieval of persistent state. There are three main overheads with remote caches:
These three overheads were treated as expected costs since there were no better solutions at the time. The only other alternative to static sharding was auto-sharding, which was not popular, mainly due to its complexity. In theory though, an auto-sharding system would solve the problems that static sharding couldn’t. The auto-sharder would shard dynamically: monitoring request load to detect hotspots, then assigning keys accordingly. If a pod goes down, its keys would get redistributed across other pods. Load would also rebalance when pods are added or removed. This would drastically reduce the need for overprovisioning and manual intervention.
If only we could come up with such a system..
Stateful services
Google’s Slicer paper was published in 2016. Slicer is Google’s auto-sharding system, one of the first real implementations the industry had seen. With the introduction of Slicer, stateful services came back into the conversation. With state cached in memory, we no longer need a remote cache. Thus, the three problems mentioned above become negligible: we no longer have to worry about a network round-trip from server to cache; since the object lives in memory, we don't need to worry about marshalling costs either; and overreads stop being a problem since we can directly access the specific fields we need on the object.
So, coupling an auto-sharding system with a stateful service makes it a feasible solution to use instead of a stateless service, right? Almost, but there is one more issue. Auto-sharders react to server failures and changes in workload by partitioning keys, but the values themselves still live on the servers. For example, let’s say a server goes down. The auto-sharder will redistribute its key mappings to the available servers, but it won't move the values. So the newly assigned server has to recover those values by reading them from the underlying storage system, which incurs an additional network hop. Even worse, if the previous server held non-persistent state (e.g. session state), that state is simply lost on key re-assignment.
LInK store
To fix this, Google created LInK store, a high level abstraction over an auto-sharder: a linked, in-memory key-value (LInK) store.

The above diagram shows the high-level architecture of LInK store. To leverage the auto-sharder, router libraries are baked into the clients. These routers cache key assignment locally and maintain a connection with Slicer for it to push assignment updates asynchronously. After receiving the request and routing it to its appropriate application server, the value is stored in a hash map through the Linklet API. The purpose of the Linklet API is to hide the internal auto-sharding details from the customer and also to provide simple APIs to read/write from the hash map. One of the more important details of LInK store, however, is its state transfer capability.
The Linklet API is responsible for performing state transfer to move values in response to key re-assignment (e.g. when a pod goes down). To do this, customers need to provide the code to (un)marshall its objects. For example, consider an e-commerce application that uses LInK store to cache each user’s shopping cart. Internally, the shopping cart schema contains a user ID, a list of items, quantities, and a timestamp. To perform the state transfer, the customer has to provide the code logic for how to (un)marshall the shopping cart into its byte representation. From LInK store’s perspective, all it’s doing is moving the byte representation from one pod to another. So the correctness of the application depends on the customer's serialization logic to ensure the shopping cart can be reconstructed properly.
Thus, the LInK store architecture solves the problems we faced with stateful services. The auto-sharder handles server failures and key assignments, while LInK store’s state transfer feature makes it so that the server does not need to re-read values from the underlying storage system whenever keys are reassigned. Stateful services are now viable and provide higher performance than their stateless alternative.
Stateful Philosophy
Although auto-sharding systems now exist, many companies have yet to migrate over to a stateful architecture. At Databricks, Atul continues to advocate for that direction, and I can clearly see it as more and more internal services begin making the switch. My internship project was also focused on improving the availability of stateful services across the company.
Since both Slicer and LInK store were systems built at Google, it’s been pretty surreal getting to talk with the people who helped create them, now over at Databricks. In fact, I had the chance to see and celebrate the open sourcing of Dicer, Databricks’ auto-sharder! We’re building plenty of other incredible services that aren’t public (yet), but I’m excited for what’s to come.
Final Thoughts
My time at Databricks was definitely busy. As you could probably imagine, a lot of it was spent trying to understand the infrastructure services my team owns. I learned a ton, but if this internship taught me anything, it's that I still have a lot more to learn.
Last summer, my time at Palantir made me want to dig deeper into distributed systems, but I wouldn’t say my curiosity has been satiated these past four months either. If anything, I’m itching even more now to dig deeper into these topics. Understanding how these systems work is one thing, and as an intern, I had plenty of opportunities to learn the theory. But building them is a completely different beast. I hope that one day I'll get to design distributed systems of my own and, hopefully, contribute something meaningful back to the broader tech ecosystem.
