Thursday, February 21, 2008

Track your [stolen] iPhone with Twitter.

Ahh. The iPhone craze is in the air. Although Apple is coming out with an official SDK for writing native apps this month, a huge community has grown around developing indie apps for the JailBroken iPhone. Some truly amazing pieces of software are cropping up, as almost all aspects of the SDK have already been reverse engineered.

Earlier today I worked a bit with Erica Sadun of TUAW on an app of her devise that runs in the background and automatically sends the triangulated geo-coordinates of your iPhone to a private Twitter account of your choice.

Now when someone slyly walks off in possession of a recently-made-theirs phone, you can literally 'follow' them and ... well, politely ask for it back?

http://www.tuaw.com/2008/02/21/tuaw-responds-iphone-lojack/

Friday, February 15, 2008

How to Build a Twitter Agent

Dominiek ter Heide had a dream. A dream of a "Twitter Service that will allow us to track the Blogosphere." So he built it, and blogged about the process! Dive in to his post to learn about building Twitter bots that talk our service via Jabber/XMPP.

If Ruby's your thing, you'll also learn about some great tools for XMPP, managing background tasks, and more in Dominiek's post. If it's not, you can take much of Dominiek's approach and apply it in your favorite language with XMMP libraries like python-xmpp for Python, XMPP.NET for C#, Gloox for C++, Smack for Java, xmpp4moz on the Mozilla platform, or one of many other libraries out there.

Jabber is great for way more than just chatting with your friends, and until now it's been up to talented developers like Dominiek to muddle their way through building Twitter bots and applications with the protocol. I'd like to put together an "official" guide to developing Jabber/XMPP applications for Twitter in the near future. Until then, soak up the knowledge that our great developer community is sharing!

Monday, February 11, 2008

Solving "The Case of the Missing Updates"

The Twitter engineering and operations team had a long week. Just several days after moving our cluster of server to a new host, we started to get reports of users missing updates. This, of course, is exactly the sort of thing we've been working to avoid by increasing our capacity and operating in a predictable, thoroughly-tested, reliable environment. So we got on the case like the Scooby gang.
scbmatMM.jpg

Tracing

While the Twitter code base has thorough test coverage for the majority of the application, many of our daemons—small programs that work on tasks retrieved from Starling queues— lack transparency into their inner workings. Tracing a message as it passes through the Twitter stack, traversing a variety of machines and services, is no mean feat. But trace we did, and we now have more "observability" built into Twitter's internals than ever before. (Plus, watching a message wind its way through our servers isn't just useful, it's also kinda neat.)

Mediating Between Starling and memcache-client

The insight gained from the tracing work helped us narrow down the potential culprits to Starling and the memcache-client library. Our newest hire, Robey, discovered that the event-driven version of Starling disconnects idle clients after 60 seconds of inactivity. Makes sense, right? Don't want to keep a zillion old connections around when you're a frequently-contacted network service...

Problem is, memcache-client doesn't check for dropped connections when doing a SET operation. We do a lot of those. Not only do we use memcache for typical cache duties, but we employ the memcache-client library as the base of our own StarlingClient library. Diagnosis: we'd inherited a couple of nasty bugs that were wrecking communication between client and server ends of the queuing system that we rely on to keep everything going. Yikes!

The solution ended up being a patch to the memcache-client library that raises a MemCacheError if an operation is unable to be completed. This allows code that wraps memcache-client to rescue and retry. Additionally, Starling has been improved with more logging and the ability to set the client timeout duration. A new public release of Starling that incorporates these fixes and improvements is coming soon.

Wrapping Up

We also fixed a handful of other minor issues with our system that should generally improve the stability of our database and memcache connections, and identified areas in which we were relying on replicated database that contained stale or inaccurate data. All this should contribute to more solid and dependable service from Twitter. With these bugs behind us, we're hoping that users and third-party developers can really see our new cluster shine!

Thursday, February 7, 2008

If You Build It, They Will Riff

The best part about open source development is seeing people riff on your code and ideas. Since opening up Starling, we've already seen a couple great contributions.

First off, righteous Ruby hackers Chris Wanstrath (of Err The Blog fame) and Kevin Clark (of Powerset) has mashed up Starling with the EventMachine library. Rather than mucking about with threads and locks, EventMachine allows Starling to operate with tidy, speedy asynchronous ease. We're already using the "evented" version of Starling in production here at Twitter, and we watched our CPU usage graphs drop as soon as we rolled it out. Thanks, Chris!

Next, the hackers at German startup play/type have created Workling, which offers several ways to ease the use of Starling with Rails. Nice work, guys!