tech-splainedpb-101

MVC 2.0: the eMail-View-Controller architecture

Published 16 days ago by sai @ pretzelbox
As we gear up to invite our next batch of Beta users to sign-up and use PretzelBox, I thought it would be good to take stock of the PretzelBox tech stack. I am particularly thrilled about one piece of our stack which is, as far as I know, unique to us - namely, Email as a backend.

In this blogpost, I will focus on how the peculiarities of email allowed us to build a webhosting offering which works brilliantly and is inherently scalable.

A brief introduction
Everything you see in PretzelBox - the blog, the file store, the PretzelBox Email inbox itself - starts with an email. You post to your blog via email. You add files to your file store via email.

And your PretzelBox Email is, of course, an inbox for your domain. 

we have ... removed the need for logging in from an entire class of user activities

Passwordless WRITEs 

man-g307a0d52c_640.jpg
Courtesy: Pixabay

Everything we do on the internet can be broken down, broadly, into two categories - READ activities and WRITE activities. In general, reading publicly available information does not need to be secured behind a login screen. On the other hand, writing (updating) information usually needs to be protected by a login.

Further, even write operations come in two flavors.

One type of update involves changing configurations and settings. In PretzelBox, this still needs a login.

The other type of Write activity involves posting to the blog or adding files to the file store. It is this last type of Write ops for which we have removed the need for logging in. You simply email your post to your blog or send an email containing attachments to save files to your file store.

While apps like Medium have implemented passwordless login, we have gone one step further and removed the need for logging in from an entire class of user activities.

If you know how to use Gmail, you are already an expert user of PretzelBox

This has three extra benefits apart from the main advantage of not needing to log into yet another website to do simple things. 
  1. Emails are auto-scanned for viruses and spam. This adds a layer of protection to your PretzelBox. In addition, if you receive emails containing attachments, you can simply forward them to your file store for auto-saving.
  2. The more subtle benefit is that you can give people the ability to send files to your file store or add a post to your blog by simply adding their email address to the list of emails allowed to write to your blog or file store. 
  3. Finally, the learning curve for PretzelBox is negligible. If you know how to use Gmail, you are already an expert user of PretzelBox
A CMS in your email

If you squint a little and look closely, each email composed in a rich text editor like Gmail is effectively a tiny CMS.

It has content along with markup clearly describing what is important and what is not. It has rich media by way of attachments and inline images. 

It has useful metadata like the name of the person sending the email and the date on which the email was received. If we make a few simplifying assumptions like say, all emails sent to blog@your-domain.com are public while all emails sent to cdn@your-domain.com are destined to go to your file store, Email also provides rudimentary access controls.

PretzelBox builds on top of this insight.

For blogs, it looks at the HTML markup of emails composed in Gmail and converts it into beautiful posts like the one you are reading right now. The name of the email sender becomes the post author. The date the email was sent is its published date.

[Learn how to write beautiful blog posts in Gmail]

The subject and body of emails sent to the File Store act as searchable text using which you can easily and quickly find files. 
 
Emails as a NoSQL Documents DB
Buzzy as it sounds, our data layer, our "Model" if you will, is quite literally a NoSQL documents db consisting of emails converted into json objects written to an S3 bucket. For PretzelBox email, the primary key of the data store is the email address to which the email was sent. 


This works well for us because email is Write-once, read-many and has a fixed internal structure. Since our "Model" is file based, we don't need to set up and pay for any database. Couple this with S3's 11 9-s reliability and we have a backend that is cheap, easy to maintain, and web scale without even trying.

Conclusion 
Email is a versatile piece of technology. For all the reports of its demise with the rise of Slack and video conferencing, it is here to stay. For example, every app under the sun needs you to have an email account to sign up. PretzelBox simply builds on top of this battle tested internet workhorse.

Here's hoping others find interesting uses of email just like we did.