Startups and .NET

Wednesday, 18 May 2011

Piehead recently blogged "Why startups could use .NET but don't". Since Showcase Lane is written in ASP.NET MVC I thought I'd share why I chose this route and and how it turned out in the end.

Firstly, here's the original article that prompted me to write this post - http://www.piehead.com/blog/2011/05/why-startups-could-use-net-but-don%E2%80%99t.

There's nothing in that post that I disagree with, except to say the cost is probably another contributing factor - both the cost of development tools and server costs - Windows based hosting tends to be more expensive than Linux hosting.

My most recent project Showcase Lane and several before it were all written and developed in ASP.NET MVC but they all run flawlessly under Mono. This lets me run it on a cheap $20/month Linode server but still get all the benefits of compiled code and awesome development tools.

In this post I thought I'd write up why I chose this approach, the final web stack that I deploy to and cover a few of the minor issues I encountered along the way.

Rationale

So the obvious first question is why I chose ASP.NET MVC as a platform. It comes down to a few simple facts:

  1. I really like C# as a language. Being a long time C++ developer I like strongly typed compiled languages and I truly believe that C# is one of the most progressive and continually improving languages available - LINQ, lambdas, anonymous types, dynamic and static typing and more. It's clean, powerful, flexible, fast and has a huge library of third party components (check out Nuget for example).
  2. Familiarity - I've used ASP.NET MVC in a number of work related projects and already new it well.
  3. Tooling - Visual Studio is in my mind the best IDE available. Powerful editing, debugging, accurate Intellisense, fast symbol browsing, fast compilation - it's all there.
  4. Mono - the ability to run on Windows or Linux based servers means no lock in and the possibility of cheaper server hosting costs.

Although I use Visual Studio 2010, I believe you could just as easily use the free Visual Studio Express editions or MonoDevelop and have a completely free development environment and web stack.

The Web Stack

Development Environment

  • OS - Windows 7 x64
  • IDE - Visual Studio 2010
  • Language - C#
  • Framework - ASP.NET MVC 2 (haven't upgraded to 3 yet, but it did work in a test project)
  • Runtime - Microsoft .NET
  • Database - MySQL (running on the staging server described below)
  • ORM - PetaPoco (of course)
  • Web Server - IIS 7
  • Deployment - IIS virtual directory pointed to project build directory.

Staging Server

  • OS - OpenSUSE 11.4 x64 on Virtual Box
  • Database - MySQL
  • Runtime - Mono 2.8
  • Web Server - Lighttpd -> Mono Fast CGI server.
  • Deployment - Visual Studio Publish tool via Samba to shared folder

Production Server

  • OpenSUSE 11.4 x64 on Linode
  • Same configuration as staging server.
  • Deployment - RSync from staging server to production server via SSH

Issues Encountered

Deploying ASP.NET MVC to Mono was smoother than I expected, but not without issues. Here's the main things I encountered:

  • Issues with Mono's Fast CGI - there are a number of critical bugs in Mono's FastCGI server - mostly comms problems between the web server and the fast CGI server. These are all resolved in Mono 2.10. Not wanting to go too bleeding edge I simply built the 2.10 fast cgi server under Mono 2.8 and haven't had any issues since.
  • MySQL data provider - you can't deploy the Windows MySQL data provider DLL to Mono 2.8 - it gives errors relating to distributed transaction support. Grabbing the latest Mono connector from the MySQL site resolved this.
  • Lighttpd's index.html - Lighttpd insists on passing "index.html" as the requested file for the root request on a domain which confuses MVC's default routing rules. I worked around this with a simple rewrite rule in the ASP.NET project (a few lines of code).
  • Image Resizing - Mono's default implementation of GDI+ yields poor quality image resampling. I resolved this by interoping to ImageMagick. See here.
  • Case Sensitivity Issues - Occasionally I've had issues with the case of view and master page filenames and with routing rules - easy to work around once you're aware of it.

Conclusion

All in all I'm really happy with the final web stack that I've settled on. It provides an excellent balance of powerful tools, a language and framework I like, the performance of a compiled code and the ability to deploy on cheap Linux servers.

One final note... I definitely planned for this web stack from the start, deliberately choosing MySQL over SQL Server and testing on both Windows/.NET and Linux/Mono each step of the way. To move to this platform after developing an entire product on Windows probably wouldn't go so smoothly.

I realize this web stack wont be to the taste of everyone, but if you're trying to decide on a platform I certainly think .NET/Mono is worth considering.

« Showcase Lane - Screen Shots PetaPoco - What's new in v4.0 »

10 Comments

It's funny, I went to a NYC .NET Meetup last night and we were discussing .NET in startups. One thing the speaker brought up was that the costs can be largely mitigated by using Microsoft's under-advertised BizSpark program... making it work with Mono is probably more fun, though!

18 May 2011 03:53 PM

I started of with a similar stack you are using, except for using nginx instead of lighttpd.. After vim-ing a bit on the server, you quickly realize that the tools you have in visual studio are nice, but not a must. After a while I moved completely to ubuntu, working with Vim and xbuild on ubuntu, testing on an openSuse vm, and deploying to an amazon opensuse.. MVC3 with Razor works easy on opensuse with mono 2.10, you can have a look on my blog for a simple script and explanation..

Nice post, Cherios!

18 May 2011 03:58 PM

Food for thought here. You've solved the problem of server costs which is a concern of mine, I will seriously consider going down this route in the future

18 May 2011 07:20 PM
dg

PlentOfFish.com has become the world's largest dating website by running the .Net stack. It uses 50x fewer servers than its competitors allowing it to be mostly a 1-man shop. Go to plentyoffish.wordpress.com and search for "asp.net" for blogs about the technical details, or search PlentyOfFish on channel9.msdn.com

18 May 2011 07:21 PM
dg

"GDI+ yields poor quality image resampling" Wha? Do image resizing on the client using Flash (many free components: plupload.com) and you'll save a mega bandwidth and server CPU.

18 May 2011 07:27 PM
antimonio

Cool! You guys are not in LinkedIn?

And no Careers section! :(

19 May 2011 01:09 PM

@dg: the image re-sampling was for showing thumbnails and smaller previews of larger images stored on the server. Where appropriate I do already do client side resizing.

20 May 2011 12:14 AM

It's great to hear such good stories about mono been deployed successfully.

20 May 2011 12:26 AM
j

This is (in spirit) almost the same setup. The only differences are that I use SubSonic, SQL Server 2008 Express on the dev machine, Ubuntu x86, and Apache. I only recently discovered PetaPoco, and will be using it from now on. That's not to say SubSonic has caused me any trouble, or slow downs for that matter. SS is good, but was generally looking for something a bit lighter, without dynamics as well.

Linode's performance has been great, no problems at all. The only difficulty I've had is when I need newer features from Mono, trying to override the prepackaged Ubuntu version is ... difficult ... to say the least.

3 June 2011 05:19 PM

At my shop we're a member of BizSpark and it is absolutely fantastic. BizSpark literally creates jobs. We were just able to hire 3 new employees, 2 developers and a web designer. If it wasn't for BizSpark we would've most likely only been able to hire the 2 developers due to the costs for licensing fees we would have spent in lieu of BizSpark.

20 July 2011 09:21 PM

Leave a comment

Name (required)
Email (required, not shown, for gravatar)
Website (optional)
Your Message
Leave these blank: