News for hackers. Stuff that matters.
Re:Unapologetically build your startup technology in C# by skrebbel on Monday July 07, 2014 @05:28AM (#7997883)
I strongly agree with the author's conclusion, but I strongly disagree with many of his points. Notably, with his recommendation to consciously go all the way with the Microsoft vendor lock in.

Our startup's backend is made in C#, and we're very happy with the choice. We use Postgres, we host it on Docker containers on Linux, and our devs are equally spread over Windows, OSX and Linux. MonoDevelop is a remarkably great IDE for something with so few users, for example, and great open source like Dapper and ServiceStack.OrmLite make it super easy for us to interface with Postgres and use all of Postgres's unique features (Json as a first class data type, multiple-cursor result sets, stuff like that).

The author seems to propose "get all the free Microsoft goodies when you start, and once you really need the paid versions you're probably successful enough that the cost doesn't matter much". It is Microsoft's strategy that companies do this, and it's a valid one, but it's really not what I would do. Microsoft might've become a whole lot more open these days, but tying yourself in so much with a single provider sounds, well, dangerous no matter what.

For example, if you develop your C# app for Azure, moving to a different provider is a lot of work (much like if you want to move your Rails app away from Heroku, but with less open source out there to ease the road). If you develop your C# app to work platform-independent (or at least cloud-provider-independent) from the outset, then you're free to move whenever you want.

Re:Unapologetically build your startup technology in C# by sirchristian on Monday July 07, 2014 @05:51AM (#7997967)
I agree "get all the free Microsoft goodies when you start, and once you really need the paid versions you're probably successful enough that the cost doesn't matter much" is one fair conclusion to the article. However I don't believe that's the only conclusion. Mostly I want .NET to be a consideration as an option when building out the technology in a startup.

I'm concerned about vender lock-in as well, just less concerned then I used to be. Microsoft's gone to great lengths to reduce some of my concerns. The fact that you are using C# with Postgres demonstrates that there doesn't need to be complete lock-in.

Do you mind sharing more about what your C#/Postgres app looks like? This combination is one option I'll be looking at for my next venture.

Re:Unapologetically build your startup technology in C# by skrebbel on Monday July 07, 2014 @07:12AM (#7998189)
OK, here goes. I'm not saying that we made the right choice all over, but this is what we currently have:

For the API we use ServiceStack (v3, because v4 is paid and has a ridiculously high license fee). It is the best-designed REST API library I've ever seen, in any language. Its focus on data and not on verbs makes it easy to build well-designed APIs and difficult to build crappy ones.

The API is the executable, self-hosting an HTTP server (using ServiceStack's support for the .NET HttpListener). We'll probably switch to FastCGI soon. In any case, we have an Nginx in front to serve all static assets, which proxies API calls through to our API.

The database layer is very lean: we rely heavily on Postgres stored procedures for much of our data logic. This way, we avoid a lot of roundtrips to the DB and back. We go as far as using Postgres's multiple cursor feature to return hierarchical data without repeating lots of data in a giant single JOIN. We then use C# to tie the pieces back together (e.g. imagine a blog example, if we'd have a query for certain posts AND their top 5 comments, we'd get one cursor for posts and one for all comments, in order, and then we tie each post to a set of comments in C#-o-world while mapping it to DTOs).

The queried data goes from what the stored procedures return straight into the DTOs that ServiceStack returns, so we have no "domain model" class structure or a heavy weight ORM. We use Dapper for easily mapping stuff to simple classes.

We insert/update data with ServiceStack.OrmLite - just simply adding rows. Often, an API DTO matches a DB table close enough that this just works without any extra mapping.

I general, we're convinced that heavy-weight ORMs don't make sense for backends which are little more than data-stores for single-page web apps.

We manage DB schema changes (and all stored procedures) using hand-written SQL scripts, much like how the Play framework does this (1.sql for the initial DB, 2.sql for changes since v1, etc). This works amazingly great, and gives us far greater control than any ORM ever gave me.

We host it all with Docker containers: one for the DB data (Docker's "data-only container" pattern), one for Postgres itself, one for the backend (running Mono 3.2.something on ubuntu 14.04), one for Nginx, and one for our static assets (so we can redeploy frontend code without restarting the nginx container). Currently, we're host it all at http://orchardup.com but we're not too happy with their very slow (but friendly) customer support. Docker has given us a bunch of headaches (for example, that data only container pattern is a lot less easy to set up in practice), but none .NET/Mono related.

Our frontend is a single-page web app, optimized for mobile, built with React and TypeScript.

Re:Unapologetically build your startup technology in C# by jtseng on Monday July 07, 2014 @11:46AM (#7999403)
We've recently started down this C#/Postgres route. One of the main decisions to use C# was static typing, so I wanted to keep this with the data access layer as well. I've decided to use dotConnect for PostgreSQL so I can use EF. I figure I can use dapper or another micro ORM after I get into performance issues.

Our biggest problem with Postgres is actually the lack of a good GUI. I'm using 0xDBE for the amazing auto complete and PgAdmin for everything else.

Re:Unapologetically build your startup technology in C# by pbz on Monday July 07, 2014 @06:23PM (#8001931)
LINQ to DB (not LINQ2SQL; it's an OSS library) is also a good option to talk to Postgres while keeping type safety and performance.
Re:Unapologetically build your startup technology in C# by JackMorgan on Monday July 07, 2014 @06:11AM (#7998035)
Why do you want .NET to be considered?
Re:Unapologetically build your startup technology in C# by ksm on Monday July 07, 2014 @12:05PM (#7999508)
Likewise, we are running our SaaS product's backend with full C# -based stack (built from scratch without using any PaaS specific technologies for IPC/RPC etc.etc. so can be run on any provider) on top of Windows VMs, but database is running in Postgres. The licensing being one of the major reasons for that and avoiding SQL Server, even though it was a technology I had lot of experience from before when I was doing IT administration in MS environments. But Postgres is not that dissimilar, at least when you tend to do lots of operations in the code and not inside the DB as storprocs..

Our client/agent piece is also written fully in C# (we support only Windows workstations at the moment so it was no-brainer decision) and recently I have been looking into Xamarin to leverage that investment when moving into other client platforms.

This has worked great as I have a history purely in Microsoft technologies so the administration is lot less of a burden compared to trying to figure out everything for some other stack. If you are fluent in one technology, why not use it, right? And besides, with Mono there's at least theoretical path for running parts of the backend on Linux, but in the big picture the licensing costs for Windows vs. Linux in managed hosting is peanuts.

Re:Unapologetically build your startup technology in C# by bigdubs on Monday July 07, 2014 @09:01AM (#7998558)
The problem with c# + postgres is you still have to run it through Npgsql which is much, much slower than the native SqlServer drive microsoft ships with the .net framework.
Re:Unapologetically build your startup technology in C# by royjacobs on Monday July 07, 2014 @06:02AM (#7998015)
Isn't ServiceStack(.OrmLite) a commercial product nowadays? Did this affect your choice in any way?
Re:Unapologetically build your startup technology in C# by skrebbel on Monday July 07, 2014 @07:14AM (#7998192)
v3 is still pretty good though. I was hoping that some eager people would fork it to keep it going, but it looks like the interest is smaller than I hoped. Maybe I'll pick it up myself one day.

The core of ServiceStack (services, messages, routes; that part) is so well designed that I simply refuse giving up on it. I think that if I were to use a different language for whatever project, I'd probably rather spend many evenings reimplementing those core concepts than going with something less good (such as the common one-method-call per URL pattern of MVC WebAPI, Rails controllers, Sinatra, Flask, etc etc etc).

I'd probably buy ServiceStack v4 if it wasn't so outrageously expensive.

Re:Unapologetically build your startup technology in C# by HarshaThota on Monday July 07, 2014 @11:27AM (#7999317)
There is a fairly active fork of ServiceStack v3 at: https://github.com/NServiceKit/NServiceKit
Re:Unapologetically build your startup technology in C# by skrebbel on Monday July 07, 2014 @02:20PM (#8000398)
Woa cool! Missed that, thanks!