I’ve been developing a new tool recently. It’s called FastInviter, and is publicly available at both its website as well as in a GitHub repository. I’ve been having a lot of fun developing it, but I hit a big snag along the way that made it seem…well, more like SlowInviter, to be honest. I wanted to talk a bit about that snag and how I managed to keep FastInviter running speedily.
Finishing Last in the Relay Race
A few days ago, I was working on email integration for FastInviter. Basically, I wanted the system to email someone when they created their events. Due to my Internet plan, unfortunately, I couldn’t send email locally – the IP address showed up on some spam blacklists, meaning that if I tried to send to, for example, a Hotmail address, I got an immediate bounceback email saying that the spam filter rejected my mail. I tried adjusting my domain’s MX record to allow my server to send, but no dice there either. The last option I had was to send through another company’s SMTP servers.
One of the nice things about CodeIgniter, the PHP framework I use for most of my development, is that it’s very easy to configure relaying mail through SMTP, even with encryption. I got everything set up in CodeIgniter, added an MX record to my domain so that the live.com servers could relay mail for me, created an event (an action set up to trigger an email alert), and…
waited for forty seconds for the page to load. Finally, it timed out, telling me that the remote server terminated the request. Turns out it was just taking far too long to talk to Live’s SMTP server, so the email I was trying to send never even made it out of my network. Relaying using CodeIgniter seemed out of the question.
I didn’t really know what to do at this point – I had pretty much exhausted all my avenues of delivery, at least that I could think of. I even tried having PHP handle the whole process without even getting CodeIgniter involved, but that led to more errors and timeouts. I had almost given up, but decided to try one more thing – setting up a SMTP server on my local server as I originally planned, but instead of sending out emails directly, instead using it as a relay to send my mail to the Live.com servers.
The procedure for doing so is a bit interesting. I configured my SMTP server as I would normally (set it up as a relay only for local mail, point it at the right directory, so on and so forth), and then went into the “Delivery” tab. In here, I had to set up the account that I had created for FastInviter to send via the Live.com server, enable TLS encryption, set the TCP port, and then add smtp.live.com as a smart host. By doing so, I basically told my server “hey, if you get mail that you’re supposed to be sending, just relay it to Live.com with the provided credentials.”
Now, the path of an email should be, as I saw it, initially getting sent from FastInviter, being received by the local server, and then getting relayed through the Live.com SMTP server. All that was left was to test it.
Speeding FastInviter Up
The test worked better than I had ever dreamed. FastInviter was loading in under a second.Having email routed locally first meant that there was no delay between the email being sent and the email being received by my server in order to relay it – any delay would be handled on the back end, where the end user wouldn’t even see it.
In addition to that, all of my problems connecting to the SMTP relay at Live.com were resolved. Having the connection handled through a local SMTP server simply made everything run way more smoothly. Combining this with my already-fast page load times made me feel like I was ready for anything.
Crossing the Finish Line
I know there’s more I could do to speed things up with FastInviter. For starters, I’m still using CDN hosted jQuery and CSS – if I bring those down and host them locally, eliminating external connections, I should be able to make the site even faster. My major concern right now is how it’ll behave once I get a bunch of events and guests going at the same time – how will the system handle that? Will my database server be able to keep up with the load? (I’ll be doing another post soon on my network architecture and how my DB server is set up). Either way, FastInviter has so far been a very fun project, and I’m looking forward to solving those problems if they do end up materializing.
I’ve taken steps to solve the problems outlined above, but there’s always going to be something new to improve. FastInviter has a live GitHub repository; if you’re interested in helping out, feel free to make changes and file a pull request! It’d be really cool to see some collaboration start cropping up on this project.