Skip to main content

Where to store the ID’s of the entities used by external services

A normal medium or complex application that discuss with different services of 3rd parties or stores data in the different repositories has different modules for each communication layer. In general, we can have a different component for each external service that is used (as in the image below).

Each external service usually has its own custom entities that are used to send data on the wire. For example the user entity for Twitter, Facebook and your own repository would be different. Each of this modules would have a wrapper for that specific service that is used over the wire (and to convert the entity to the POCO of the specific service).

It is not important where the logic from the yellow box is (in the same class, in different class or modules). But in one way or another we would have something like this.
The logic of your application could work with specific objects that are defined only in your application. For example you could have your own entity User, which would contains all the attributes and functionality that are supported by your application.

Let’s assume that the entity that is stored in DB is called UserDB, the own used by Facebook module is called UserFB and the one for Twitter is UserTW. For example when you want to save the attributes from User to the DB, you would need to obtain an instance of UserDB, update the fields and save them. It is not important where this action take place for us for now. Our question is how you need to identify the UserDB entity for the given user?
One possibility would be store the UserDB ID from the database in our application (in User or in another location). This action would happen for UserFB and UserTW. This may be a good solution that would work for us.
If we could not identify the user with other unique identification attributes, this solution may be the only one that we could use.
The only thing that is happening in this situation is that you create an indirect reference from your logic module that contains the User entity to the other external services (modules).  Even if this is not a direct reference, you have an information that can be found in User and is used to identify the unique user in other services used by your application.
A possible solution would be to create a mapper in each modules user to communicate with different services (in the wrapper module), that can match and get the unique id of the user for each external services.
This solution may be better than the one that has the UserDB id, UserFB id and UserTW id in the User entity, but you would have to manage the mapping between them (this is not all the time an easy task).

The happiest scenario is to have in the User entity some attributes that can be used to unique identify a user in each services that is used. For example the social number can be used in the UserDB and user email could be used for Facebook and Twitter. In this way we would not need the mapper between different entities in each module. It would be pretty simple to retrieve the entity that it is needed based on this information. In this case we would not need anymore the mapper, we could directly retrieve the entity from the service based on the specific attribute(s)

What other solutions would you try to use?

Comments

  1. The biggest problem with storing a reference/id in the User class/entity to each external service is that it doesn't play nice with open-closed principle - each time support for a new external service will have to be implemented in the application, the User class will have to be modified..
    Better would be to reverse the dependency - in a class specific to that external service to store a reference to the User class.

    ReplyDelete
    Replies
    1. @Tudor, this is another good ideas. Is similar with the Mapper from each external service module, that can map the logic entity (app entity) to the one used by external service.

      Delete

Post a Comment

Popular posts from this blog

Windows Docker Containers can make WIN32 API calls, use COM and ASP.NET WebForms

After the last post , I received two interesting questions related to Docker and Windows. People were interested if we do Win32 API calls from a Docker container and if there is support for COM. WIN32 Support To test calls to WIN32 API, let’s try to populate SYSTEM_INFO class. [StructLayout(LayoutKind.Sequential)] public struct SYSTEM_INFO { public uint dwOemId; public uint dwPageSize; public uint lpMinimumApplicationAddress; public uint lpMaximumApplicationAddress; public uint dwActiveProcessorMask; public uint dwNumberOfProcessors; public uint dwProcessorType; public uint dwAllocationGranularity; public uint dwProcessorLevel; public uint dwProcessorRevision; } ... [DllImport("kernel32")] static extern void GetSystemInfo(ref SYSTEM_INFO pSI); ... SYSTEM_INFO pSI = new SYSTEM_INFO(

Azure AD and AWS Cognito side-by-side

In the last few weeks, I was involved in multiple opportunities on Microsoft Azure and Amazon, where we had to analyse AWS Cognito, Azure AD and other solutions that are available on the market. I decided to consolidate in one post all features and differences that I identified for both of them that we should need to take into account. Take into account that Azure AD is an identity and access management services well integrated with Microsoft stack. In comparison, AWS Cognito is just a user sign-up, sign-in and access control and nothing more. The focus is not on the main features, is more on small things that can make a difference when you want to decide where we want to store and manage our users.  This information might be useful in the future when we need to decide where we want to keep and manage our users.  Feature Azure AD (B2C, B2C) AWS Cognito Access token lifetime Default 1h – the value is configurable 1h – cannot be modified

What to do when you hit the throughput limits of Azure Storage (Blobs)

In this post we will talk about how we can detect when we hit a throughput limit of Azure Storage and what we can do in that moment. Context If we take a look on Scalability Targets of Azure Storage ( https://azure.microsoft.com/en-us/documentation/articles/storage-scalability-targets/ ) we will observe that the limits are prety high. But, based on our business logic we can end up at this limits. If you create a system that is hitted by a high number of device, you can hit easily the total number of requests rate that can be done on a Storage Account. This limits on Azure is 20.000 IOPS (entities or messages per second) where (and this is very important) the size of the request is 1KB. Normally, if you make a load tests where 20.000 clients will hit different blobs storages from the same Azure Storage Account, this limits can be reached. How we can detect this problem? From client, we can detect that this limits was reached based on the HTTP error code that is returned by HTTP