Alejandro G. Carlstein Ramos Mejia Blog



 icon-arrow-left Microservices: Brownfield: Transactions

The support reporting for our micro-services architecture system can be a little complex. At difference to a monolithic architecture where you may have a few databases to report from, in the micro-services architecture system, you will have a tons of databases to report from since each micro-service will have its own database.

The report of the data will come from the be split across multiple micro-services and since there is no a central database where you could extract this information you may need to join data across databases. Also, in the micro-service architecture system, reporting can be slow. 

One way to facilitate the reporting is to have a dedicated reporting micro-service which calls all our micro-services and takes care of collecting and consolidate the data. The only disadvantage is when we are reporting large volumes of data or we wish to obtain a report in real-time.

Share

 icon-arrow-left Microservices: Brownfield: Migration: Database | Microservices: Brownfield: Reporting icon-arrow-right 

When moving from a monolithic system to a micro-service architectured system, we need a different approach when dealing with transactions.

Transactions are useful:

  • They ensure data integrity.
  • They allow us to updates several records as part of one transaction.
  • If one or more updates (and/or creates) fails, we can roll the entire transaction back.

In monolithic transactions are simple. We can have one process which is updating and creating records. These records are part of the transaction; therefore, the same process can either commit the transaction or roll it back if there are any issues.

Share

Added my logo to the website and copyright it.

Alejandro G. Carlstein Ramos Mejia Logo

Share

In this example you will see: feffects, feffects.Tween, flash.external.ExternalInterface.

NOTIFICATION: These examples are provided for educational purposes. Using this code is under your own responsibility and risk. The code is given ‘as is’. I do not take responsibilities of how they are used.

Code Example: Example_10_Sprite2D.hx:

/**
 * @author: Alejandro G. Carlstein R. M.
 * @description: In order to use Tweener you have to install the feffects
 * Install: neko-dev (Ubuntu: sudo apt-get Eneko-dev)
 * Execute: haxelib install feffects
 *	 Compile with flag: -lib feffects
 *	 Tweens available: feffects.easing.
 *	 Quint.easeIn, Quint.easeOut, Quint.easeInOut
 *	 Sine.easeIn, Sine.easeOut, Sine.easeInOut
 *	 Back.easeIn, Back.easeOut, Back.easeInOut
 *	 Bounce.easeIn, Bounce.easeOut, Bounce.easeInOut
 *	 Circ.easeIn, Circ.easeOut, Circ.easeInOut
 *	 Cubic.easeIn, Cubic.easeOut, Cubic.easeInOut
 *	 Elastic.easeIn, Elastic.easeOut, Elastic.easeInOut
 *	 Expo.easeIn, Expo.easeOut, Expo.easeInOut
 *	 Linear.easeIn, Linear.easeOut, Linear.easeInOut, Linear.easeNone
 *	 Quad.easeIn, Quad.easeOut, Quad.easeInOut
 *	 Quart.easeIn, Quart.easeOut, Quad.easeInOut
 *
 */

import feffects.Tween;
import feffects.easing.Bounce;
import feffects.easing.Circ;
import feffects.easing.Elastic;
import flash.text.TextField;
import flash.display.Sprite;

class NumericBall2D extends Sprite{
	private var text_field : TextField;
	private static var LINE_SIZE : Float = 1.0;
	private static var LINE_COLOR : Int = 0x000000;
	private static var FILL_COLOR : Int = 0x11FF33;
	private static var CIRCLE_X : Int = 0;
	private static var CIRCLE_Y : Int = 0;
	public function new(size : Float = 25){
		super();
		graphics.lineStyle(LINE_SIZE, LINE_COLOR);
    graphics.beginFill(FILL_COLOR);
	  graphics.drawCircle(CIRCLE_X, CIRCLE_Y, size);
    graphics.endFill();

	  text_field = new TextField();
		flash.Lib.current.addChild(text_field);
	}

	public function setText(text : String){
		text_field.text = text;
	  text_field.x = this.x - 12;
	  text_field.y = this.y - 40;
	}
}

class Example_10_Sprite2D{

    private var numericBall2D : NumericBall2D;
    private var tween : Tween;
		private static var MIN_Y : Int = 100;
		private static var MAX_Y : Int = 300;
		private static var EFFECT_DURATION : Int = 5000;

    public function new(?x : Float){
        numericBall2D = new NumericBall2D();
        numericBall2D.x = x;
        flash.Lib.current.addChild(numericBall2D);

        tween = new Tween(MIN_Y, MAX_Y, EFFECT_DURATION, Elastic.easeOut );
        tween.setTweenHandlers(moveY, msgFinished );
        trace ( 'tween staring at position: ' + MIN_Y);
        tween.start();
    }

    function moveY( position : Float ){
        numericBall2D.setText(Std.string(Math.round(position)));
        numericBall2D.y = position;
    }

    function msgFinished( position : Float ){
        trace ( 'tween finished at position: ' + position );
    }

}

example_10.hx:

Share

NOTIFICATION: These examples are provided for educational purposes. The use of this code and/or information is under your own responsibility and risk. The information and/or code is given ‘as is’. I do not take responsibilities of how they are used.

In this example you will see: Binary search by using heapsort for sorting.

example_5.hx:

/**
 * @author: Alejandro G. Carlstein R. M.
 */

class HeapSort{

	private var data : Array<Int>;
	private var heap_size : Int;
	private inline function leftChild(index : Int) : Int{ return (index << 1) + 1;	}
	private inline function rightChild(index : Int) : Int{ return (index << 1) + 2; }

	// Constructor ( ? means that items is optional)
	public function new(?data : Array<Int>){
		this.data = (data == null) ? new Array() : data;
	}

	public function getData() : Array<Int> {
		return data;
	}

	public function setData(data : Array<Int>) : Void {
		this.data = data;
	}

	public function sort() : Void{
		if(data.iterator().hasNext()){
			heap_size = data.length;
			buildMaxHeap();
			var index : Int = data.length - 1;
			while (index > -1){
				exchange(0, index);
				maxHeapify(0, --heap_size);
				--index;
			}
		}else{
			trace('There is no data to sort');
		}
	}

	private function buildMaxHeap() : Void{
		var index : Int = data.length >> 1;
		while (index > -1){
			maxHeapify(index, heap_size);
			--index;
		}
	}

	private function maxHeapify(index : Int, heapSize : Int) : Void{
		var largest : Int = index;
		var left : Int = leftChild(index);
		var right : Int = rightChild(index);	

		if (left < heapSize && data[left] > data[index])
			largest = left;

		if (right < heapSize && data[right] > data[largest])
			largest = right;

		if (largest != index){
			exchange(index, largest);
			maxHeapify(largest, heapSize);
		}
	}

	private function exchange(index_a : Int, index_b : Int) : Void{
		var temp_value : Int = data[index_a];
		data[index_a] = data[index_b];
		data[index_b] = temp_value;
	}

}

class BinarySearch{
	private var heapsort : HeapSort;
	private var data : Array<Int>;
	private function search(value : Int, start_index : Int, end_index : Int){
		var middle_index : Int = (start_index + end_index) >> 1;
		var was_found : Bool = false;
		if(start_index < end_index){
			if(data[middle_index] == value){
				return true;
			}else{
				if(data[middle_index] > value){
					was_found = search(value, start_index, middle_index);
				}else{
					was_found = search(value, middle_index + 1, end_index);
				}
			}
		}
		return was_found;
	}

	// Constructor ( ? means that items is optional)
	public function new(?data : Array<Int>){
		this.data = (data == null) ? new Array() : data;
		if (data != null) setData(data);
	}

	public function getData() : Array<Int> {
		return data;
	}

	public function setData(data : Array<Int>) : Void {
		if (data != null){
			heapsort = new HeapSort();
			heapsort.setData(data);
			heapsort.sort();
			data = heapsort.getData();
		}
	}

	public function doExist(value : Int) : Bool{
		return search(value, 0, data.length);
	}

}

class Example_5 {

	static function main(){

		var data : Array<Int> = [3, 7, 5, -1, 6, 1, -3];
		printData(data);

		trace('Binary Search:');
		var binarySearch = new BinarySearch(data);
		trace ('Do 3 exist? ' + binarySearch.doExist(3));
		trace ('Do 4 exist? ' + binarySearch.doExist(4));
		trace ('Do 7 exist? ' + binarySearch.doExist(7));

		data = binarySearch.getData();
		printData(data);		

	}

	private static function printData(data : Array<Int>){
		var iter = data.iterator();
		var index : Int = 0;
		trace('[DATA]');
		while (iter.hasNext()){
			trace('data[' + index++ + ']: ' + iter.next());
		}
	}

}

If you encounter any problems or errors, please let me know by providing an example of the code, input, output, and an explanation. Thanks.

Share

02/25/2013

I wish to do my master degree in computer science; however, there is a requirement I need to fulfill first which is the Graduate Record Examination (GRE). This exam is a requirement for many universities.

In some universities, you don’t need to take the GRE before starting your master; however, this condition apply only if you are starting your master degree right after you graduate with your bachelor degree. The only rule in many universities is that you accomplish the GRE before you finish your masters.

In my case, I decided to get a job instead of continuing with my education. I don’t like loans or owe anything to anyone; therefore, I need to make sure I have the funds to continue my education without getting in debt.

Share

As you may know, Microsoft is getting into the open source community with the ASP.NET and DNX with the mono project.
The .NET Execution Environment (DNX) is a software development kit which allows you to run .NET applications on Windows, Mac, and Linux using different frameworks such as .NET framework, .NET Core, and Mono. However, everything isn’t roses. There are many incomplete libraries, incompatibilities, lack of documentation, and most of the examples such as doing SQL or SOAP do not work depending on which the library targets you are planning to code for. Therefore, I decided to test the basics on all the library targets. I am starting with DNX451.

The task parallel library seems to be working fine in DNX451 with C#. Below is a code example for those who wish to play with it.

 

Program.cs

Share