SOLVED

Redesign web application > Move from SQL-server to CosmosDB (or not)

%3CLINGO-SUB%20id%3D%22lingo-sub-140910%22%20slang%3D%22en-US%22%3ERedesign%20web%20application%20%26gt%3B%20Move%20from%20SQL-server%20to%20CosmosDB%20(or%20not)%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-140910%22%20slang%3D%22en-US%22%3E%3CP%3EI%20try%20to%20find%20as%20much%20information%20as%20possible%20about%20CosmosDB%20but%20have%20not%20found%20my%20answer%20yet.%3C%2FP%3E%0A%3CP%3EWe%20have%20a%20(kind%20of)%20straight%20forward%20web%20application%20(Classic%20ASP%2C%20Javascript%2C%20MS%20SQL%20server).%20We%20have%20to%20move%2Fredesign%20this%20application%20to%20Azure%20(possibly%20.Net).%20We%20are%20not%20sure%20to%20use%20CosmosDB.%20Our%20current%20sql%20database%20is%20(of%20course)%20relational%20and%20uses%20a%20lot%20of%20stored%20procedures.%26nbsp%3B%3C%2FP%3E%0A%3CP%3EWhy%20should%20we%20use%2C%20or%20not%20use%2C%20CosmosDB%3F%20Price%20is%20also%20something%20we%20need%20to%20consider.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ECan%20someone%20help%20us%20out%20to%20make%20the%20best%20decision%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-140910%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EAzure%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-141262%22%20slang%3D%22en-US%22%3ERe%3A%20Redesign%20web%20application%20%26gt%3B%20Move%20from%20SQL-server%20to%20CosmosDB%20(or%20not)%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-141262%22%20slang%3D%22en-US%22%3E%3CP%3EHi%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F93174%22%20target%3D%22_blank%22%3E%40Joshua%20Carlisle%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EI'll%20take%20your%20advice%20%3B)%3C%2Fimg%3E%3C%2FP%3E%0A%3CP%3EI%20did%20find%20some%20kind%20of%20%22solution%22%20meanwhile%20but%20also%20noticed%20it%20would%20not%20be%20safe%3A%3C%2FP%3E%0A%3CPRE%3Evar%20settings%20%3D%20%7B%0A%20%20%22async%22%3A%20true%2C%0A%20%20%22crossDomain%22%3A%20true%2C%0A%20%20%22url%22%3A%20%22https%3A%2F%2Ftest.documents.azure.com%3A443%2Fdbs%2Ftempdb%2Fcolls%2Ftempcoll%2Fdocs%2FWakefieldFamily%22%2C%0A%20%20%22method%22%3A%20%22GET%22%2C%0A%20%20%22headers%22%3A%20%7B%0A%20%20%20%20%22Accept%22%3A%20%22application%2Fjson%22%2C%0A%20%20%20%20%22x-ms-version%22%3A%20%222016-07-11%22%2C%0A%20%20%20%20%22Authorization%22%3A%20%22%7B%7BauthToken%7D%7D%22%2C%0A%20%20%20%20%22x-ms-date%22%3A%20%22%7B%7BRFC1123time%7D%7D%22%2C%0A%20%20%20%20%22Cache-Control%22%3A%20%22no-cache%22%2C%0A%20%20%20%20%22Postman-Token%22%3A%20%227146132a-75b2-39e2-001d-afeafb4e0d5d%22%0A%20%20%7D%2C%0A%20%20%22data%22%3A%20%22%7B%5Cr%5Cn%20%20%20%20query%3A%20%5C%22SELECT%20*%20FROM%20c%5C%22%2C%5Cr%5Cn%20%20%20%20parameters%3A%20%5B%5D%5Cr%5Cn%7D%5Cr%5Cn%22%0A%7D%0A%0A%24.ajax(settings).done(function%20(response)%20%7B%0A%20%20console.log(response)%3B%0A%7D)%3B%3C%2FPRE%3E%0A%3CP%3EI%20guess%20I%20have%20to%20sort%20out%20node.js.%20It's%20kind%20of%20new%20for%20me%20but%20that%20keeps%20me%20busy.%3C%2FP%3E%0A%3CP%3EJust%20for%20testing%20I'll%20try%20to%20use%20a%20classic%20ASP%20connection%20first%20and%20then%20try%20to%20rebuild%20it%20to%20node.js.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-141256%22%20slang%3D%22en-US%22%3ERe%3A%20Redesign%20web%20application%20%26gt%3B%20Move%20from%20SQL-server%20to%20CosmosDB%20(or%20not)%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-141256%22%20slang%3D%22en-US%22%3E%3CP%3EMost%20of%20the%20Javascript%20examples%20you'll%20find%20will%20be%20using%20Node.js%20on%20the%20server.%20CosmosDB%20does%20have%20a%20REST%26nbsp%3Binterface%20that%20could%20technically%20be%20used%20on%20the%20client%20side%20from%20javascript%5Cjquery%20but%20that%20would%20not%20be%20a%20best%20practice%20by%20any%20means%20and%20I%20would%20highly%20discourage%20it%20-%20you%20have%20no%20safe%20place%20to%20store%20your%20credentials.%26nbsp%3B%20Your%20CosmosDB%20calls%20should%20be%20made%20from%20a%20trusted%20location%20and%20should%20not%20be%20considered%20for%20use%20as%20an%20API%20layer%26nbsp%3Bbeing%20called%20directly%20from%20some%20javascript%20in%20a%20browser.%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3Ee.g.%20Client%20-%26gt%3B%20API%20Host%20-%26gt%3B%20CosmosDB%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThere%20are%20a%20lot%20of%20options%20for%20that%20REST%20API%20layer%20on%20Azure%20ranging%20from%20your%20traditional%20API%20built%20in%20Node%20(Javascript)%20or%20ASP.NET%20to%20newer%20serverless%20offerings%20such%20as%20Azure%20Functions%20but%20in%20the%20end%20the%20reason%20you%20can't%20find%20examples%20is%20because%20you%20shouldn't%20do%20it%20%3A)%3C%2Fimg%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ECheers%2C%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EJosh%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-141220%22%20slang%3D%22en-US%22%3ERe%3A%20Redesign%20web%20application%20%26gt%3B%20Move%20from%20SQL-server%20to%20CosmosDB%20(or%20not)%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-141220%22%20slang%3D%22en-US%22%3E%3CP%3EI%20did%20some%20digging%20today%20for%20examples.%20I%20just%20want%20an%20simple%20example.%20Create%20a%20demo%20CosmosDB%20and%20use%20plain%20javascript%2Fjquery%20to%20access%20the%20data.%20Is%20there%20an%20example%20out%20there%20which%20I%20can%20rebuild%20myself%3F%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EI%20did%20find%20this%20example%3A%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fcosmos-db%2Fsql-api-nodejs-application%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fcosmos-db%2Fsql-api-nodejs-application%3C%2FA%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EBut%20I%20would%20like%20to%20do%20something%20like%20this%3A%3C%2FP%3E%0A%3CPRE%3E%20%20%20%20%24.ajax(%7B%0A%20%20%20%20%20%20url%3A%20_rootSiteURL%20%2B%20%22%2F_api%2Fsearch%2Fquery%3Fquerytext%3D'blabla'%2C%0A%20%20%20%20%20%20method%3A%20%22GET%22%2C%0A%20%20%20%20%20%20headers%3A%20%7B%22accept%22%3A%20%22application%2Fjson%3Bodata%3Dverbose%22%7D%2C%0A%20%20%20success%3A%20function(xData%2C%20request)%7B%0Ablabala.....%0A%3C%2FPRE%3E%0A%3CP%3EIf%20this%20is%20even%20possible..%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-141138%22%20slang%3D%22en-US%22%3ERe%3A%20Redesign%20web%20application%20%26gt%3B%20Move%20from%20SQL-server%20to%20CosmosDB%20(or%20not)%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-141138%22%20slang%3D%22en-US%22%3E%3CP%3EHi%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F93174%22%20target%3D%22_blank%22%3E%40Joshua%20Carlisle%3C%2FA%3Ethanks%20a%20lot.%20This%20give%20me%20a%20good%20start!%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-141026%22%20slang%3D%22en-US%22%3ERe%3A%20Redesign%20web%20application%20%26gt%3B%20Move%20from%20SQL-server%20to%20CosmosDB%20(or%20not)%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-141026%22%20slang%3D%22en-US%22%3E%3CP%3ESo%20this%20is%20a%20pretty%20broad%20question%20and%20tough%20to%20answer.%20The%20frustrating%20and%20truthful%20answer%20is%20%22it%20depends%22%26nbsp%3Bbut%26nbsp%3Bto%20be%20clear%20though%20you%20can%20be%20successful%20with%20both.%26nbsp%3B%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EI%20have%20several%20CosmosDB%20implementations%20behind%20me%20and%20I'm%20a%20big%20proponent%20but%20in%20my%20experience%20to%20be%20successful%20it%20does%20take%20a%20mental%20shift%20from%20the%20traditional%20relational%20normalized%20data%20models%20that%20has%20been%26nbsp%3Bingrained%20into%20the%20industry%20(and%20our%20heads)%20for%20the%20last%2030%20years.%26nbsp%3B%26nbsp%3BI%20still%20work%20regularly%20with%20traditional%20relational%20databases%20but%20there%20are%20several%20aspects%20of%20CosmosDB%20that%20continually%20lead%20me%20to%20frequently%20recommend%20it.%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3EServerless%20-%20I'm%20not%20maintaining%20a%20server%2C%20worrying%20about%20CPU%20and%20memory%2C%20worrying%20about%20storage%2C%20worrying%20about%20disk%20IO%2C%20worrying%20about%20redundancy%2C%20etc.%26nbsp%3B%20Huge%20overall%20reduction%20in%20devops%20efforts%20and%20costs.%26nbsp%3B%20Allows%20me%20to%20concentrate%20more%20on%20app%20and%20not%20the%20infrastructure.%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FLI%3E%0A%3CLI%3EDevelopment%20Model%20-%20I%20find%20I'm%20more%20efficient%20working%20with%20a%20simple%20JSON%20Data%20Model%20and%20the%20CosmosDB%20(DocumentDB)%20API%20over%20the%20equivalent%20traditional%20database%20development%20whether%20that%20be%20Entity%20Framework%20or%20more%20legacy%20stored%20procedure%20heavy%20solutions.%26nbsp%3B%26nbsp%3BMind%20you%20still%20have%20to%20plan%5Cdesign%20your%26nbsp%3Bdata%20model%20well%20(partition%20keys%2C%20etc).%3C%2FLI%3E%0A%3CLI%3ECosts%20-%20%26nbsp%3BIn%20our%20experience%20so%20far%20we've%20felt%20pretty%20strongly%20that%20we've%20had%20significant%20costs%20saving%20over%20traditional%20Azure%20SQL%20instances%20that%20would%20provide%20us%20the%20equivalent%20performance%20and%20redundancy%20(not%20even%20counting%20more%20abstract%20operational%20and%20devops%20costs).%26nbsp%3B%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3ESaying%20that%20I've%20had%20some%20frustrations%20and%20challenges%20-%20standing%20out%20in%20my%20mind%3A%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3EAggregates%20-%20CosmosDB%20has%20limited%20support%20for%20aggregates%20that%20is%20REALLY%20challenging.%26nbsp%3B%20They%20say%20they%20do%20but%20they%20don't%20support%20common%20aggregates%20such%20as%20distinct%20and%20group%20by%20(yet).%26nbsp%3BIf%20you%20need%20to%20have%20aggregates%20this%20could%20be%20a%20headache%20for%20you.%3C%2FLI%3E%0A%3CLI%3ECase%20Sensitive%20-%20Queries%20are%20all%20case%20sensitive%20requiring%20extra%20work%20or%20having%20canonicalized%20versions%20of%20common%20search%20fields%20(e.g.%20lower%20case%2C%20etc)%3C%2FLI%3E%0A%3CLI%3ELookup%20Values%20-%20Establishing%20a%20pattern%20I%20liked%20for%20things%20like%20lookup%20values%20(think%20dropdowns)%20and%20managing%20those%20values.%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3EYou%20also%20have%20extra%20considerations%20with%20migrating%20legacy%20data.%20If%20you%20are%20thinking%20of%20a%20%22life%20and%20shift%22%20to%20the%20cloud%20or%20if%20you%20have%20a%20lot%20of%20business%20logic%20in%20your%20stored%20procedures%20then%20you%20may%20have%20a%20lot%20of%20work%20ahead%20of%20you%20and%20it%20may%20be%20worthwhile%20to%20stay%20with%20SQL%20Server.%26nbsp%3B%20You'll%20also%20have%20to%20think%20about%20migrating%20your%20existing%20data.%20Some%20application%20are%20just%20naturally%20more%20relational%20and%20belong%20in%20SQL.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EI%20really%20suggest%20you%20pull%20down%20some%20sample%20projects%20off%20of%20github%20and%20get%20a%20feel%20for%20the%20development%20experience.%20THere%20is%20a%20local%20emulator%20so%20you%20can%20do%20it%20for%20free.%26nbsp%3B%26nbsp%3BExperiment%20a%20little%20on%20the%20impact%20on%20your%20data%20model%20and%20how%20you%20query%20and%20use%20your%20data.%20If%20you%20have%20a%20%22close%22%20data%20model%20you%20can%20plug%20it%20into%20a%20cost%20calculator%20and%20get%20some%20general%20costs%20-%20running%20some%20sample%20queries%20will%20also%20give%20you%20some%20RU%20costs%20for%20those%20queries%20which%20might%20help%20you%20refine%20those%20estimates%20even%20further.%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EHope%20this%20helps%20a%20little.%20Good%20luck!%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E
Highlighted
Regular Contributor

I try to find as much information as possible about CosmosDB but have not found my answer yet.

We have a (kind of) straight forward web application (Classic ASP, Javascript, MS SQL server). We have to move/redesign this application to Azure (possibly .Net). We are not sure to use CosmosDB. Our current sql database is (of course) relational and uses a lot of stored procedures. 

Why should we use, or not use, CosmosDB? Price is also something we need to consider.

 

Can someone help us out to make the best decision?

5 Replies
Highlighted
Best Response confirmed by Mike Jansen (Regular Contributor)
Solution

So this is a pretty broad question and tough to answer. The frustrating and truthful answer is "it depends" but to be clear though you can be successful with both.  

 

I have several CosmosDB implementations behind me and I'm a big proponent but in my experience to be successful it does take a mental shift from the traditional relational normalized data models that has been ingrained into the industry (and our heads) for the last 30 years.  I still work regularly with traditional relational databases but there are several aspects of CosmosDB that continually lead me to frequently recommend it.

  • Serverless - I'm not maintaining a server, worrying about CPU and memory, worrying about storage, worrying about disk IO, worrying about redundancy, etc.  Huge overall reduction in devops efforts and costs.  Allows me to concentrate more on app and not the infrastructure.

  • Development Model - I find I'm more efficient working with a simple JSON Data Model and the CosmosDB (DocumentDB) API over the equivalent traditional database development whether that be Entity Framework or more legacy stored procedure heavy solutions.  Mind you still have to plan\design your data model well (partition keys, etc).
  • Costs -  In our experience so far we've felt pretty strongly that we've had significant costs saving over traditional Azure SQL instances that would provide us the equivalent performance and redundancy (not even counting more abstract operational and devops costs). 

Saying that I've had some frustrations and challenges - standing out in my mind:

  • Aggregates - CosmosDB has limited support for aggregates that is REALLY challenging.  They say they do but they don't support common aggregates such as distinct and group by (yet). If you need to have aggregates this could be a headache for you.
  • Case Sensitive - Queries are all case sensitive requiring extra work or having canonicalized versions of common search fields (e.g. lower case, etc)
  • Lookup Values - Establishing a pattern I liked for things like lookup values (think dropdowns) and managing those values.

You also have extra considerations with migrating legacy data. If you are thinking of a "life and shift" to the cloud or if you have a lot of business logic in your stored procedures then you may have a lot of work ahead of you and it may be worthwhile to stay with SQL Server.  You'll also have to think about migrating your existing data. Some application are just naturally more relational and belong in SQL.

 

I really suggest you pull down some sample projects off of github and get a feel for the development experience. THere is a local emulator so you can do it for free.  Experiment a little on the impact on your data model and how you query and use your data. If you have a "close" data model you can plug it into a cost calculator and get some general costs - running some sample queries will also give you some RU costs for those queries which might help you refine those estimates even further. 

 

Hope this helps a little. Good luck!

 

 





Highlighted

Hi @Joshua Carlisle thanks a lot. This give me a good start!

Highlighted

I did some digging today for examples. I just want an simple example. Create a demo CosmosDB and use plain javascript/jquery to access the data. Is there an example out there which I can rebuild myself?

 

I did find this example: https://docs.microsoft.com/en-us/azure/cosmos-db/sql-api-nodejs-application

 

But I would like to do something like this:

  		$.ajax({
    		url: _rootSiteURL + "/_api/search/query?querytext='blabla',
    		method: "GET",
    		headers: {"accept": "application/json;odata=verbose"},
			success: function(xData, request){
blabala.....

If this is even possible..

Highlighted

Most of the Javascript examples you'll find will be using Node.js on the server. CosmosDB does have a REST interface that could technically be used on the client side from javascript\jquery but that would not be a best practice by any means and I would highly discourage it - you have no safe place to store your credentials.  Your CosmosDB calls should be made from a trusted location and should not be considered for use as an API layer being called directly from some javascript in a browser. 

 

e.g. Client -> API Host -> CosmosDB 

 

 

There are a lot of options for that REST API layer on Azure ranging from your traditional API built in Node (Javascript) or ASP.NET to newer serverless offerings such as Azure Functions but in the end the reason you can't find examples is because you shouldn't do it :) 

 

Cheers,

 

Josh

 

 

 

Highlighted

Hi @Joshua Carlisle 

I'll take your advice ;)

I did find some kind of "solution" meanwhile but also noticed it would not be safe:

var settings = {
  "async": true,
  "crossDomain": true,
  "url": "https://test.documents.azure.com:443/dbs/tempdb/colls/tempcoll/docs/WakefieldFamily",
  "method": "GET",
  "headers": {
    "Accept": "application/json",
    "x-ms-version": "2016-07-11",
    "Authorization": "{{authToken}}",
    "x-ms-date": "{{RFC1123time}}",
    "Cache-Control": "no-cache",
    "Postman-Token": "7146132a-75b2-39e2-001d-afeafb4e0d5d"
  },
  "data": "{\r\n    query: \"SELECT * FROM c\",\r\n    parameters: []\r\n}\r\n"
}

$.ajax(settings).done(function (response) {
  console.log(response);
});

I guess I have to sort out node.js. It's kind of new for me but that keeps me busy.

Just for testing I'll try to use a classic ASP connection first and then try to rebuild it to node.js.