Thursday, May 30, 2024

Exploring the Most Widely Used Software and System Architectures Today

     In the rapidly evolving world of technology, the architectural foundations of software and systems play a pivotal role in shaping how we interact with digital services and products. Today, several architectural paradigms dominate the landscape, each bringing unique advantages that cater to the diverse needs of modern enterprises. This blog post delves into the most widely used software and system architectures, highlighting their features, benefits, and real-world applications.

 1. Microservices Architecture

     Microservices architecture has become a cornerstone for modern application development. Unlike monolithic architectures, where all components are interwoven into a single system, microservices break down applications into smaller, independent services. Each microservice focuses on a specific business function and communicates with others through well-defined APIs.

 Benefits:

- Scalability: Individual services can be scaled independently, allowing for more efficient resource utilization.

- Flexibility: Teams can develop, deploy, and manage services independently, fostering a more agile development process.

- Resilience: Failure in one microservice does not necessarily bring down the entire system, enhancing overall system stability.

 Applications: Companies like Netflix, Amazon, and Spotify leverage microservices to handle their vast, dynamic user bases and complex operations.

 2. Serverless Architecture

     Serverless architecture represents a shift from traditional server management to a model where cloud providers dynamically manage the allocation and provisioning of servers. Developers write and deploy code in the form of functions, and the cloud provider executes these functions only when needed.

 Benefits:

- Cost Efficiency: Charges are based on execution time and resources consumed, eliminating the cost of idle infrastructure.

- Simplicity: Developers focus solely on writing code without worrying about server maintenance or infrastructure management.

- Scalability: Functions automatically scale with the demand, ensuring optimal performance without manual intervention.

 Applications: AWS Lambda, Google Cloud Functions, and Azure Functions are popular serverless platforms used in various scenarios, from data processing to real-time file processing.

 3. Containerization and Kubernetes

    Containerization, often associated with Docker, involves encapsulating applications and their dependencies into containers. Kubernetes, an open-source orchestration platform, manages containerized applications across a cluster of machines, ensuring automated deployment, scaling, and management.

 Benefits:

- Portability: Containers can run consistently across different environments, from development to production.

- Efficiency: Containers share the host OS kernel, making them lightweight and fast to start compared to traditional virtual machines.

- Orchestration: Kubernetes provides robust tools for managing large-scale container deployments, handling load balancing, scaling, and more.

 Applications: Organizations like Google, Airbnb, and Goldman Sachs use Kubernetes to manage their containerized applications, ensuring reliability and scalability in their operations.

 4. Cloud-Native Architecture

     Cloud-native architecture is designed specifically to leverage cloud environments, encompassing a range of practices such as microservices, containerization, and DevOps. It emphasizes the use of cloud services, infrastructure as code, and continuous integration/continuous deployment (CI/CD) pipelines.

 Benefits:

- Resilience: Cloud-native applications are designed to handle failures gracefully, with built-in redundancy and automated recovery.

- Agility: Rapid development and deployment cycles enable organizations to respond quickly to market changes and user feedback.

- Cost Optimization: Leveraging cloud services allows for dynamic resource allocation, optimizing costs based on actual usage.

 Applications: Companies like Uber, Shopify, and Pinterest exemplify cloud-native approaches, utilizing the cloud's full potential to deliver robust, scalable, and agile applications.

 5. Event-Driven Architecture

     Event-driven architecture (EDA) revolves around the production, detection, consumption, and reaction to events. This asynchronous communication model decouples event producers from consumers, enabling more flexible and scalable systems.

 Benefits:

- Decoupling: Components can operate independently, improving modularity and reducing interdependencies.

- Scalability: Systems can handle varying loads efficiently by responding to events in real-time.

- Responsiveness: EDA supports real-time processing and decision-making, enhancing user experiences.

 Applications: Financial services, e-commerce platforms, and IoT applications often employ EDA to process transactions, manage inventories, and handle sensor data in real-time.

 Conclusion

     The landscape of software and system architectures is continually evolving, driven by the need for scalability, flexibility, and efficiency. Microservices, serverless, containerization, cloud-native, and event-driven architectures each offer unique advantages that cater to different requirements and challenges. By understanding and leveraging these architectures, businesses can build resilient, scalable, and responsive systems that meet the demands of today’s fast-paced digital world.

Wednesday, October 28, 2020

Editing bacpac file before importing


The bacpac file I have generated from Azure SQL had a reference to an external resource - that I do not require. Hence, when I was importing the database locally it was failing. Clearly, I need to remove the reference to the external data source.

As I do, googled, and got couple of solutions :

  • Change collation of an Azure SQL database by hacking the BACPAC file : Very helpful to know what exactly need to be done to copy an Azure SQL Db to local SQL server. When I tried create the cheksome of the model.xml file - it was saying invalid dacpac file - (quite obvious as mine was a bacpac file not dacpac)
  • Editing a .bacpac file : Then this microsoft article helped me creating a PowerShell script - which did not quite working for me - ( I am on a Windows 10 machine, possibly and using different PowerShell ? - did not get enough time to investigate further).
  • Get-FileHash : PowesrShell to generate checksum for files : Finally, found the command that helped me to generate the checksum for the file as explained in other two articles. (BTW, I had to remove all the reference to the external data source)
voilà - now I need to start my actual task - track the transactions in the database for some front end activity and finally create SQL script to generate test data. 

Thursday, March 23, 2017

Salesforce (SFDC) as an Identity Provider (Idp)

Started to implement SSO for one of my project without knowing anything.
Trying to note down to identify the bits and pieces here.
Steps followed :

  1. Set up a dev account with Salesforce. https://developer.salesforce.com/signup
  2. Playing with Salesforce how SAML based authentication works in there : https://developer.salesforce.com/docs/atlas.en-us.identityImplGuide.meta/identityImplGuide/identity_quickstart_SAMLgen.htm
  3. Set up a custom web application (SP-service provider) to work with Salesforce (Idp) : https://developer.salesforce.com/page/Configuring-SAML-SSO-to-Custom-.Net-Application
  4. Step 4 din cover how I can actually redirect to a particular page after successful login. Utilising the  RelayState parameter.

When sending Authentication request pass the RelayState parameter as below :
On AssertionConsumerServiceUrl check for the RelayState url parameter is passed back :

Issues I will be working on next are :
1. Registration - how it works from custom website
2. How it will works for manual approval for registered users.Any api or else ?
3. How the authentication works through this custom site wide - do I need to ping every time to Idp ?

Ultimate goal is to prepare a project template that can be reused.

Thursday, April 21, 2016

Opensource PDF generator : wkhtmltopdf

wkhtmltopdf and wkhtmltoimage are open source (LGPLv3) command line tools to render HTML into PDF and various image formats using the Qt WebKit rendering engine. These run entirely "headless" and do not require a display or display service.
There is also a C library, if you're into that kind of thing.
I am writhing this post just to keep record of what actually worked for me - the command I mean.

PATH_TO_wkhtmltopdf\bin\wkhtmltopdf --header-spacing 14 -T 22mm --header-html header.html cover cover.html toc --xsl-style-sheet toc-default.xsl article.html article_to_publish.pdf 
The command above prints a page as pdf with cover page, table of contents and header The TOC layout used is generated using a command as bellow:
PATH_TO_wkhtmltopdf\bin\wkhtmltopdf --dump-default-toc-xsl >> toc-default.xsl
Full document can be found here, which definitely I din find quite qood. 

Wednesday, September 16, 2015

LINQ: Problem with Deferred execution

This morning I started my day googling for an exception in the code:
Some part of your SQL statement is nested too deeply. Rewrite the query or break it up into smaller queries
And as most cases, I ended up with a Stackover solution:


The code that I was cleaning up was as bellow:


This was breaking for large data but working fine for small data.

It was breaking when the Except() is used to compare large data – the reason is EF most cases does Deferred execution- so all the incompleteCourseId, completedCourseId and requeriedCourseId are evaluated when the Except() is called. For small data it can execute – but for large data it breaks.

Similar thing can happen when complex query needs to be executed through LINQ; So possibly its a good idea to split the queries into multiple ones and evaluate whenever required/whenever requires fetching large data.

So the solution is I forcefully evaluated each of the query using ToList() and it seems it is working good now. Off course cost is multiple SQL call.

Reference:
http://stackoverflow.com/questions/14163390/some-part-of-your-sql-statement-is-nested-too-deeply-rewrite-the-query-or-break


Monday, June 15, 2015

Passing EventArguments to RelayCommand in MVVM

I was to override the default behavior of the editable ComboBox control. Where if clicked the in the combobox the text will always be selected.

The View :
<ComboBox x:Name="cboList" FontSize="25"
     TabIndex="8" MaxDropDownHeight="270"
     Style="{DynamicResource ComboBoxStyleLargeScroll}"
     DisplayMemberPath="Name" SelectedValuePath="RepID"
     ItemsSource="{Binding VisitorHostList, UpdateSourceTrigger=PropertyChanged
   ,ValidatesOnExceptions=True, ValidatesOnDataErrors=True, NotifyOnValidationError=True}"
     SelectedItem="{Binding UpdateSourceTrigger=PropertyChanged, ValidatesOnExceptions=True, ValidatesOnDataErrors=True
   ,NotifyOnValidationError=True, Path=SelectedVisitorHost}"
     SelectedValue="{Binding Inductee.HostRepID, UpdateSourceTrigger=PropertyChanged
   ,ValidatesOnExceptions=True, ValidatesOnDataErrors=True, NotifyOnValidationError=True}" IsEditable="True" VerticalContentAlignment="Bottom" MinWidth="0" MaxWidth="351">
                                    <ComboBox.Resources>
                                        <Style TargetType="{x:Type ScrollBar}">
                                            <Setter Property="Width" Value="50" />
                                        </Style>
                                    </ComboBox.Resources>
                                    <i:Interaction.Triggers>
                                        <i:EventTrigger EventName="GotFocus">
                                            <cmd:EventToCommand Command="{Binding GotFocusCommand, Mode=OneWay}" MustToggleIsEnabledValue="True"/>
                                        </i:EventTrigger>
                                        <i:EventTrigger EventName="PreviewMouseUp">
                                            <cmd:EventToCommand Command="{Binding PreviewMouseUpCommand, Mode=OneWay}" MustToggleIsEnabledValue="True" PassEventArgsToCommand="True" />
                                        </i:EventTrigger>

                                    </i:Interaction.Triggers>
                                </ComboBox>
The ViewModel :
#region Commands
  public ICommand PreviewMouseUpCommand { get; set; }
 #endregion
#region Constructor
        public MyViewModel()
        {
         
            PreviewMouseUpCommand = new RelayCommand<MouseButtonEventArgs>(PreviewMouseUp);
         
        }
#endregion
#region eventhandler
private void PreviewMouseUp(MouseButtonEventArgs e)
        {
            try
            {
                System.Windows.Controls.ComboBox cboHostList = e.Source as System.Windows.Controls.ComboBox;
                if (cboHostList != null)
                {
                    var cboEditableTextBox = (cboHostList.Template.FindName("PART_EditableTextBox", cboHostList) as System.Windows.Controls.TextBox);
                    if (cboEditableTextBox != null && !cboHostList.IsDropDownOpen)
                    {
                        Application.Current.Dispatcher.BeginInvoke(new Action(() =>
                        {
                            cboEditableTextBox.SelectAll();
                            cboEditableTextBox.Focus();
                        }));
                    }
                }
            }
            catch(Exception ex)
            {
                Util.Logger(typeof(MyViewModel)).Error("Error in PreviewMouseUp of ComboboxList", ex);
            }
        }
#endregion

Friday, May 22, 2015

Custom ActionFilter in ASP .Net MVC

I had a scenario like if a person doesn't have proper access to a resource he will receive a message on a page.
Initially I thought I should implement custom Authorization Filter [customize the existing Authorization Filter] - but it looked like Authorization filter is implemented [at least in my application] more like if the filter is not met you are redirected to login page - kind of session checking and stuffs like mandatory things for each of the Actions.
But in my case I was putting this check on a single Action - off course having option to reuse the filter later.
Following is the Controller with Filter:

[Authorize]
[PermittedSiteActionAttribute]
public ActionResult Siteinfo(int id = 0, string nodeType = "")
{
RASSiteDetailsModel model = null;
return View(model);
}

The  PermittedSiteActionAttribute lokked like :
public class PermittedSiteActionAttribute : FilterAttribute, IActionFilter
    {
        bool _IsAuthorised = false;
        void IActionFilter.OnActionExecuted(ActionExecutedContext filterContext)
        {
            try
            {
                if (!_IsAuthorised)
                {
                    filterContext.Controller.ViewData.Model = null;
                }
            }
            catch (Exception ex)
            {
                Logger.Error("Error in PermittedSiteActionAttribute>OnActionExecuted", ex);
            }
        }
        void IActionFilter.OnActionExecuting(ActionExecutingContext filterContext)
        {
            try
            {
                var actionParams = filterContext.ActionParameters;
                object siteId;
                actionParams.TryGetValue("id", out siteId);
                if (siteId != null && decimal.Parse(siteId.ToString()) > 0)
                {
                    Util util = new Util();
                    _IsAuthorised = util.IsPermittedSite(decimal.Parse(siteId.ToString()));
                }
                if (!_IsAuthorised)
                {
                    filterContext.Controller.ViewBag.AuthorizationMessage = "You are not Authorised to access this resource; Please select a different site.";
                }
            }
            catch(Exception ex)
            {
                Logger.Error("Error in PermittedSiteActionAttribute>OnActionExecuting", ex);
            }
        }
    }
Here OnActionExecuting event I am checking the permission and if fails I am setting the Model to be Null at OnActionExecuted event - so that the user doesn't views the resource returned by the Action. May be not the perfect way of doing this - but a way around, I guess :)

To get started with these Asp .Net Action filters following tutorial is a good one:


Open source Push Server

  • PushSharp: [C#] :A server-side library for sending Push Notifications to iOS (iPhone/iPad APNS), OSX (APNS 10.8+) Android (C2DM and GCM - Google Cloud Message), Chrome (GCM) Windows Phone, Windows 8, Blackberry (PAP), and Amazon (ADM) devices!
  • PushSharp.Web: [C#] A web wrapper for PushSharp
  • AeoroGear UnifiedPushSeerver: [JAVA]: Easy and promising - does have a Openshift gear and can be tested over Openshift
  • Pushd:[Node.js] :Pushd is a pluggable "unified" push server for server-side notification to mobile native apps, web apps etc. With pushd you can send push notifications to any supported mobile platform, web app or HTTP server from a single entry point. Pushd takes care of which device is subscribed to which event and is designed to support an unlimited amount of subscribable events.
  • Loopback.io: [Node.js]: Loopback is basically a nodejs framework to easily create api - but it does have component to create push servers.
  • Node-Push-Server: [Node.js]: It looks like a stripped down version of Pushd.

Thursday, May 21, 2015

Logging in DotNet applications

  • log4net: log4net from Apache is a library tool to help the programmer output log statements to
    a variety of output targets. log4net is a port of the excellent Apache log4j™ framework to the Microsoft® .NET runtime. We have kept the framework similar in spirit to the original log4j while taking advantage of new features in the .NET runtime.
  • ELMAHELMAH (Error Logging Modules and Handlers) is an application-wide error logging facility that is completely pluggable. It can be dynamically added to a running ASP.NET web application, or even all ASP.NET web applications on a machine, without any need for re-compilation or re-deployment.For asp.net applications to log without putting any code inside the applications

WCF vs Asp.Net Web API

When I first learnt about Web API, I got confused - as I was always doing the RESTful services using the WCF - why then another way to accomplish the same thing ?

WCF ASP.Net WEB API
  • Back-end Services
  • SOAP, WS-*
  • Transporst: HTTP, UDP, TCP, QUEUES, Custom
  • Message Patterns: request-response, one-way, duplex
  • Use WCF Web HTTP to add HTTP endpoints to existing WCF Services
  • Use WCF Data Services for full OData support
  • Front-end Services
  • Media Type: JSON, XML, form-URL-encoded, Custom
  • Request-reply only
  • REST, resource centric
  • Use SignalR for asynchronous signaling (polling, long-polling, WebSockets)

For further reference: