Thursday, May 14, 2020

Think before going Microservices

The goal of microservices is to sufficiently decompose the application in order to facilitate agile application development and deployment.

The following is based on the book Microservices from Design to Deployment from NGINX. My goal is to know the difficaulties that this inevitable is bringing with in order to be prepared for.

The Drawbacks of Microservices

  1. One drawback is the name itself. The term microservice places excessive emphasis on service size. While small services are preferable, it’s important to remember that small services are a means to an end, and not the primary goal.

  2. Another major drawback of microservices is the complexity that arises from the fact that a microservices application is a distributed system. Developers need to choose and implement an inter-process communication mechanism based on either messaging or RPC. Moreover, they must also write code to handle partial failure, since the destination of a request might be slow or unavailable.

  3. Another challenge with microservices is the partitioned database architecture. Using distributed transactions is usually not an option, and not only because of the CAP theorem. They simply are not supported by many of today’s highly scalable NoSQL databases and messaging brokers. You end up having to use an eventual consistency-based approach, which is more challenging for developers.

  4. Testing a microservices application is also much more complex. A simple test class for a service
    would need to launch that service and any services that it depends upon, or at least configure stubs for those services.

  5. Another major challenge with the Microservices Architecture pattern is implementing
    changes that span multiple services. Fortunately, most changes typically impact only
    one service; multi-service changes that require coordination are relatively rare.

  6. Deploying a microservices-based application is also much more complex.

  7. Each service will have multiple runtime instances. That’s many more moving parts that
    need to be configured, deployed, scaled, and monitored. In addition, you will also need to
    implement a service discovery mechanism that enables a service to discover the locations
    (hosts and ports) of any other services it needs to communicate with.

Sunday, June 24, 2018

Writing That Works

  • The foundations of effective business writing are simplicity and accuracy. 
  • emails: 
    • subjects are adequate
    • use positive tone
    • get to the point quickly and write only what's relevant
    • etiquette is key
    • be explicit about your questions and requests
  • well-structured and focused presentations and speeches
    • engage your audience
    • finish with small memorable notes
    • use titles that builds anticipation
  • Drive people to action with clear plan and reports
    • purpose statement
    • facts
    • recommendations
    • purpose of the report should be clear and interesting
  • Speak to your reader's desire and concerns
    • State what you want and offer your reasoning after the facts
    • demonstrate your competence with background information
    • grab reader's attention 
  • Write a summary in bold
  • Edit and format your final product
    • cut out anything you think is not essential 
    • is the order correct
    • fact check
    • give yourself enough time between drafts, and have another person review 
    • format for smooth and appealing experience


How to: Write documentation

Questions to ask:

  • Does the document fulfill its purpose?
  • Is anything missing?
  • Can anything be taken out?
  • What questions will the reader have? And answer them.
  • Is the writing easy to understand?

Also Check:

  • Sentence and paragraph structure
  • Grammar
  • Word choice
  • Spelling


pluralsight - technical-writing-software-documentation

Writing That Works 

Monday, February 20, 2017

Force HTTPS Rule

<system.webServer>
  <rewrite>
    <rules>
      <rule name="Force HTTPS" enabled="true">
        <match url="(.*)" ignoreCase="true"/>
        <conditions>
          <add input="{HTTPS}" pattern="off"/>
        </conditions>
        <action type="Redirect" url="https://{HTTP_HOST}/{R:1}"/>
      </rule>
    </rules>
  </rewrite>
</system.webServer>

Tuesday, January 7, 2014

IIFE

IIFE stands for: Immediately-Invoked Function Expression
It is a self-executing anonimous function like this:


(function($){
    $.fn.myplugin = funnction(options) {
        var settings = {};
        $.extend(settings, this.myPlugin.defaults, options);
        return this;
    };

    $.fn.myPlugin.defaults = {
        option1: 'option1',
        option2: 'option2',
        option3: 'option3'
    };
})(jQuery);


Another good example:

// Create an anonymous function expression that gets invoked immediately,
// and assign its *return value* to a variable. This approach "cuts out the
// middleman" of the named `makeWhatever` function reference.
// 
// As explained in the above "important note," even though parens are not
// required around this function expression, they should still be used as a
// matter of convention to help clarify that the variable is being set to
// the function's *result* and not the function itself.

var counter = (function(){
  var i = 0;

  return {
    get: function(){
      return i;
    },
    set: function( val ){
      i = val;
    },
    increment: function() {
      return ++i;
    }
  };
}());

// `counter` is an object with properties, which in this case happen to be
// methods.

counter.get(); // 0
counter.set( 3 );
counter.increment(); // 4
counter.increment(); // 5

counter.i; // undefined (`i` is not a property of the returned object)
i; // ReferenceError: i is not defined (it only exists inside the closure)


Source: http://benalman.com/news/2010/11/immediately-invoked-function-expression/

Tuesday, June 18, 2013

Passing Date parametere from Javascript to WCF

Having a service method that accepts two parameters will look like this:

[DataContract()]
public class ServiceRequest
{
    [DataMember()]
    Nullable<DateTime> DateTimeFrom { get; set; }
    [DataMember()]
    Nullable<DateTime> DateTimeTo { get; set; }
}

[ServiceContract()]
public interface IService
{
    [WebInvoke(UriTemplate = "getServiceCall", Method = "POST")]
    ServResponse GetBusinessObjects(ServiceRequest filter);
}
Now, To start calling this method we need to construct a Json data representing the parameters.
      var fromDate = new Date(2013, 06, 18);
      var toDate = new Date();

      var datavar = {
            DateTimeFrom: fromDate.toMSJSON(),
            DateTimeTo: toDate.toMSJSON()
      };
      var parameters = JSON.stringify(datavar); 

But, before calling the toMSJSON on date object we need to define it as follows:


// Let Date type be compatible for Microsoft WCF
Date.prototype.toMSJSON = function () {
/// <summary>Let Date type be compatible for Microsoft WCF.</summary>
var date = '/Date(' + this.getTime()  + '-0000)/';
};

Getting DateTime from WCF

// convert WCF date to Javascript
String.prototype.DateWCF = function () {
    /// <summary>convert string into Date</summary>
    var matches = this.match(/\/Date\(([0-9]+)(?:.*)\)\//);
    if (matches)
        return new Date(parseInt(matches[1]));
};
Notice that when you use a date in javascript it is representing your local date based on the settings on your systemn and browser. As a result you might pass different notation to WCF. For example, my broweser has an timezone offset of -120 minutes. So when I ask to convert 06/20/2013 02:10:04 I see 2013-06-20T00:10:04.000Z which is perfectly normal because that represents the same exact time as I meant on my browser. Thus WCF will get the correct date aswell.

Friday, April 5, 2013

Minify js and css files in Visual Studio 2012

Finally we got an integrated tool in VS2012 that does the jobin Solution Explorer:
Web Essentials
You can enable this tool using the Extensions And Updates from the TOOLS menu.


  1. First, right-click on the css file and from the Web Essentials context menu choose to Minify CSS Files. This will ensure that with every build it will generate the accompanying .min.css file too.
  2. Make sure you have the Web.Release.config beside your web.config
  3. In your .aspx or .master file put an if statement to figure out if this is running on your debug mode or release mode:
.
 <% if (HttpContext.Current.IsDebuggingEnabled) { %>
    <link href="/css/MyFile.css" rel="stylesheet" type="text/css"></link>
  <%} else {%>
    <link href="/css/MyFile.min.css" rel="stylesheet" type="text/css"></link>
  <%} %>
.