How FriendFeed uses MySQL to store schema-less data

This is beautiful! Check out this post on Bret Taylor’s blog:

We use MySQL for storing all of the data in FriendFeed. Our database has grown a lot as our user base has grown. We now store over 250 million entries and a bunch of other data, from comments and “likes” to friend lists.

As our database has grown, we have tried to iteratively deal with the scaling issues that come with rapid growth. We did the typical things, like using read slaves and memcache to increase read throughput and sharding our database to improve write throughput. However, as we grew, scaling our existing features to accomodate more traffic turned out to be much less of an issue than adding new features.

After some deliberation, we decided to implement a “schema-less” storage system on top of MySQL rather than use a completely new storage system. This post attempts to describe the high-level details of the system. We are curious how other large sites have tackled these problems, and we thought some of the design work we have done might be useful to other developers.

Which Fonts Are Web-safe in 2009?

Below is an excerpt from Issue 56 of the Sitepoint Design View newsletter that I found very interesting and useful. Perhaps you will too.

Alex Walker
Editor, SitePoint Design View

For the past five years, have run an ongoing font survey, analyzing the system fonts of visitors to their site. Although the sample group is likely skewed towards the designers and developers that frequent their site, it’s arguably still the best information we currently have on font availability in 2009.

Although it’s true that the Web’s font ecosystem evolves at a glacial pace, sometimes years can pass without us considering what fonts are currently available.

Today I thought we might have a fresh look at the font landscape, and consider some options that might bring freshness to your design without any loss of compatibility.

Palatino Linotype (Win)

At the risk of illiciting a duh from those who use this font often, I’m starting out with Palatino Linotype — in my view the Web’s most under-utilized font.

Why? Well, firstly it has a great pedigree. The original Palatino was a graceful calligraphic serif designed by legendary type designer Hermann Zapf in 1948.

Microsoft then employed Hermann to revise the font for screen usage in the Windows 2000 release, giving us Palatino Linotype. The font has since been included with Office 2003, Office 2007, WinXP, Vista, and presumably Windows 7, making it virtually ubiquitous on the platform.

Palatino Linotype is friendly yet refined, classy but informal in larger type sizes and still reading well down to 12px.

Despite these many and varied attractions, it’s still surprisingly little used online. Google reports the text fragment ‘font-family:Palatino Linotype’ appears 7,750 times, compared to 617,000 for ‘font-family:Times New Roman’. Amazing really.

And this despite the fact that CodeStyle now reports Palatino Linotype as far MORE common (97%) than Times New Roman (88%).

Some might argue that both Georgia and Constantia are similar and prettier (but less common), and I’ll happily agree and encourage you to list them first in your stack.

Regardless of your number one font choice, I think you would have to question why you’d ever list Times New Roman again. Period.

Century Gothic (Win)

I’ve always liked the clean geometric lines of Bauhaus design so I have a soft spot for Century Gothic.

Designed as a revival of Sol Hess’s 1930s-era Twentieth Century, Century Gothic is a very engineered yet elegant typeface. I’ve seen it used on everything from cosmetics to horse racing to prestige hotel sites.

Although I prefer to limit its use to headers, subheaders, and opening paragraphs, it still reads well at 12px — though it’s arguably uncomfortable [KS: or uneasy or awkward] on the eye in large slabs.

Shipping with the last two versions of MS Office, Century Gothic is reported to be present on a respectable 85% of PCs. MS Trebuchet (96%) provides a visually passable fallback on Windows and Futura (90%) provides a good match on Macs.


Calibri (Win)

Calibri is, I believe, the best san-serif option of the clutch of new fonts released with Microsoft Vista, Office 2007, and Office 2008 for Mac.

Unfortunately, the less than enthusiastic uptake of Vista has slightly stunted the proliferation of what is a very good screen font. Currently none of the new fonts released with Vista are even a 50/50 chance to be found on any given Windows system. And that’s a little sad.

However, if you’d like to own Calibri (or any of its sibling fonts, Candara, Consolas, Cambria, Constantia, and Corbel), they are generally available.

Last time I checked, all of these fonts were freely included with:

Calibri is always described as a humanist font, which I think makes it the kind of font you’d be pleased to take home to meet mother. It’s approachable and a bit touchy-feely, and does its best work as body text.

There are two small caveats to using it, however:

  1. A rendering bug in Firefox 2 caused some of the Vista “C” fonts to disappear at certain sizes. Be sure to thoroughly test your pages in that browser before settling on it.
  2. Calibri seems to render smaller on the Mac, so be careful using it with layouts that require your text to fill a certain amount of space.

Lucida Grande (Mac)

Okay, so if you’re a Mac user, you’re likely to be intimately acquainted with Lucida Grande by now and probably rolling your eyes at this recommendation. In fact, you probably see it everywhere you go, from CSS Zen Garden to Facebook.

However, if you’re a Windows user who routinely lists Helvetica as “the Mac font” — and you could do worse — Lucida Grande is for you.

The original Lucida fonts were designed by Charles Bigelow and Kris Holmes in the mid-eighties. More of an extended font clan than nuclear family, Lucida now contains more than a dozen variants — including serifs, san-serifs, handwritten, and calligraphic styles, and even mathematics and specialized fax faces.

Lucida Grande is installed with all OS X installations and Code Style reports it present in over 90% of surveyed machines.

The cool aspect for Windows users is that the font comes free with Safari for Windows. All you need to do is locate it in the Safari folder and copy it to the fonts folder:

C:\Program Files\Safari\Safari.resources

Grande is awful purdy for body text, and it has decent Windows visual equivalents in Calibri (mentioned above), Lucida Unicode, and Trebuchet MS (in that order).

It does seem to render a little smaller on the Mac, so be aware of that when testing. Otherwise, consider giving Helvetica a breather.

Rules for Practical Programmers

Here are some observations I’ve gathered from writing a variety of programs in PHP over the last year. Do you have one I should add? Please share it and post it in the comments.

1) Don’t waste time re-inventing the wheel unless you can make a significantly better one.

Custom frameworks have their advantages, but are really necessary only if you are developing a particularly unusual project or actually have time to invest in writing framework. There are several great frameworks out there which are mature, tested, and have communities, all time-saving assets which no business-smart programmer should overlook.

Can’t find a framework that suits perfectly? Consider forking one.

2) Pretty code syntax should not be more important than re-usable code.

Case in point: static class methods nice and easy to use, but only if you don’t ever need to extend them (that is, until PHP 5.3 is production-ready). Make code decisions on the basis of functionality and intended use rather than “prettiness.”

3) Learning to use design patterns will save time in the long run, but don’t overdo it.

Remember the law of diminishing returns.

4) Comment religiously, and make your code easy to read, too.

This involves descriptive variable names, following code style conventions, etc. Make comments useful: “# Assign the variable” tells me nothing I can’t already see.

PHP Syntax Highlighting Refresh

When you spend your days staring at PHP code, you really can appreciate a visual refresh now and then. Syntax highlighting, if done well, makes reading code much easier. Excellent color schemes are not only functional, but are visually appealing as well.

Personally, I think Eclipse PDT’s PHP syntax highlighting is quite boring. I have tried several custom color schemes, but here is one I particularly like.

Do you have syntax color schemes you like? Post them in the comments.


Logical XOR in Javascript

XOR (exclusive OR) is a boolean operation, like && and ||, but with the following logic: It is true if the expression on either side is true (like ||), but not if both sides are true (like &&).

Sometimes, in your JavaScript, you might want to do the following:

if( foo XOR bar ) { ... }

Unfortunately, JavaScript does not have a logical XOR operator. This article covers several methods of performing an XOR manually, and concludes with a surprisingly succinct way of doing it, summarized below.

The cleanest and best

The XOR operation can be described as “return true if the two boolean operands do not have the same value”. So the actual response that is wanted is just this:

if( foo != bar ) { ... }

That works if the two operands are both boolean true/false. However, to allow for other variable types (strings, expressions, etc.), it cannot work, since ‘string’ does not equal /regex/, even though the XOR operation would be expected to return false. So the operands need to be converted into boolean values first. This can be done like this:

foo ? true : false

However, it is easier and quicker to simply use the ! operator. This will give the opposite value – false instead of true, but as long as both operands get the same treatment, this will not affect the end result. So the simplest, cleanest version of the XOR operator, that works with any data types, including expressions, is this:

if( !foo != !bar ) { ... }

Hello! I’m a self-taught freelance web developer, and this is my blog. Here, I document problems and solutions in PHP, MySQL, and Javascript that I encounter along the way. Enjoy!