Archive for the 'Toolbox' Category

Programmer’s Toolbox Part 3: Consistent Hashing

Next up in the toolbox series is an idea so good it deserves an entire article all to itself: consistent hashing.

Let’s say you’re a hot startup and your database is starting to slow down. You decide to cache some results so that you can render web pages more quickly. If you want your cache to use multiple servers (scale horizontally, in the biz), you’ll need some way of picking the right server for a particular key. If you only have 5 to 10 minutes allocated for this problem on your development schedule, you’ll end up using what is known as the naïve solution: put your N server IPs in an array and pick one using key % N.

I kid, I kid — I know you don’t have a development schedule. That’s OK. You’re a startup.

Continue reading ‘Programmer’s Toolbox Part 3: Consistent Hashing’

5 more essentials for your programming toolbox

Following up on my first post, What should be in your programming toolbox, here are a few more ideas from my list:

Unrolled Linked Lists

Wikipedia has more details, but essentially, an unrolled linked list is great because it will give you better performance than a regular linked list, is more cache friendly, and will probably have much less overhead. The basic idea is to store an array of elements at each node rather than a single one. This keeps your pointers closer together, which will make your cache happy when you are iterating through your items.

Continue reading ’5 more essentials for your programming toolbox’

What should be in your programming toolbox?

I really enjoy writing the code that makes systems like Audiogalaxy and FolderShare run. Getting into the zone and really getting some good work done is a great experience, but remains my second favorite aspect of the job. For me, the best part is the design phase before the real coding starts. At that point, everything is totally fluid and malleable. I’m making the decisions that I’m going to live with for the next few years, and putting some extra cleverness or flexibility into the system can have huge payoffs.

Something I’ve found very helpful at this phase is a “programming toolbox” — a simple list of good ideas and approaches to different problems. When I’m stuck on a problem, or trying to generate a new approach to something, it can be helpful to flip through the list. Most of the ideas won’t apply, but sometimes it will spark something novel. To keep this list from getting too unwieldy, I’ll post a few at a time as I write them up.

Continue reading ‘What should be in your programming toolbox?’