instruction
stringlengths
34
36.1k
I am trying to explore the patterns around data integrity when applying multiple services with access to the same storage. Let's say I have Service1, which runs in 3 instances. Whenever an instance of Service1 persists some data to the underlying storage, I would like to enforce that data is not somehow corrupted based...
I'll first explain the context of my problem. The backend of my current project is using DDD, CQRS and Event Sourcing as a stack (the read DB being a MongoDB, my write DB being an event store). At some point I had to chain multiple commands in a "transactional" manner, did some research and had to choose between listen...
I'm designing an application which accepts a command, processes it and produces a result. Application will maintain the status of the input command as 'new', 'processing' and 'completed' as it transition through the execution flow. When the command processing is completed, status will be updated to 'completed'. But it...
I work for a publishing company that also provides content distribution to their users. In order to access a piece of content the user must be entitled to do so. Traditionally this authorization check has been done with several different ways (most of them legacy, unsecure and, tbh, very ugly). We do support username a...
The team I'm in creates components that can be used by the company's partners to integrate with our platform. As such, I agree we should take extreme care when introducing (third-party) dependencies. Currently we have no third-party dependencies and we have to stay on the lowest API level of the framework. Some example...
as per my current requirement. I would like to maintain common source code for different country releases. Below are the cases which are required to be covered in the new process of code manage. Release new feature for one country only and once that feature works perfectly we will release that feature in other countr...
I am diving in the domain driven design (DDD) and while I go more deeply in it there are some things that I don't get. As I understand it, a main point is to split the Domain Logic (Business Logic) from the Infrastructure (DB, File System, etc.). What I am wondering is, what happens when I have very complex queries lik...
I have an Event Sourced system that has 3 micro services (simplified): User management - Registering a user, change password etc User account - manages debiting/crediting of the user account balance Notifications - email notifications when balance changes I have a requirement that we want to have Demo users that can ...
I know very little about encryption, so I figured I'd ask the internet if it's possible to do the following (and if so, what kind of algorithm should I be looking at): Write some code that saves data to and loads data from a file, however the file is usable only once. What I mean is that the data is loaded in from it, ...
Based on what I've read, user stories are often cast in a "who", "what", and "why" format, i.e. "[Who] wants the system to do [What], so that [Why]". The "who" and "what" seem easy to grasp. For the example of an ATM: As a customer I want to be able to deposit money [Why] The "why" line seems like it could have a...
My team has a mix of software developers and scientists, and version control has been messy in the past. We're trying to do better, which leads me to ask this question. We have a central codebase for a subset of projects that includes code for different tools all sharing common algorithms. Let's call that U1. There are...
I encountered this string that looks like JSON syntax but I've never seen a property with a colon before it and not with a backwards greater than or equals sign: Badge { :id=>36, :name=>"Appreciated", :default_icon=>"fa-heart", :badge_type_id=>3, :query=>"", :default_badge_grouping_id=>2, ...
I came across this word "implementation". CPython is one of the most common implementations of Python. What exactly is an implementation? I researched a bit on how a Python code runs. First, it is compiled and converted into bytecode and then, using PVM or interpreter (not sure), it is converted into machine language w...
I research about [association] in use case diagram : It is a line has not arrow as image: https://www.uml-diagrams.org/use-case-actor-association.html But i using Rational Rose: If i draw a [association], it is a line has arrow: Is it ok? Association in Use Case diagram have arrow?
I had a simple static method which would take a value and a unit type (pounds, gallons, dollars) and would just format a string. A simplified example: public static string Format(decimal value, UnitType unit) { ... if(unit == UnitType.Dollars) { return "$" + value; } ... } Now, the requireme...
I have a simple design question. I have a tree based C++ class. It needs to use a distance function in order to calculate nearest neighbors. But the distance function is available from an external library such as GeographicLib or others. Ideally you want to vary the distance function based on client preferences. If the...
I'm developing a C# WPF desktop application where I need to read/write to an SQL database regularly. Now I want to map the data from the database to objects in C#. I can't use Entity Framework so I'm doing all my data access through Dapper, slapper automapper and stored procedures. I know of this very similar question...
I was looking for an easy implementation of the Event Sourcing and CQRS Pattern in ASP.NET Core using Azure Cosmos DB as Event Store. As I couldn't find anything appropriate I decided to write a solution using the mentioned technology stack on my own. The ASP.NET Core Backend receives commands, creates events and write...
I am working on an internal application that is maintained by the same people that operate the servers the application runs on. We have noticed, while transitioning from Windows to Linux, that some instances of this application are hitting the default limit on the number of open file handles allowed per process[1]. We ...
I'm using OAuth 2.0 with Laravel (Passport) in order to grant access to my frontend app to the API. Access tokens generated this expires after a while. Now, I have a second app that has to consume the same API but sessions in this app must not expire. I need to get tokens with no expiration for this app. Right now, I i...
Many of the server scripting packages/tools out there have the option to have a schema validation before the response is sent out to the clients. E.g. the fastify package for a Node.js has a pretty upfront one. Only two use cases that I can think of is restricting excess data and security. I feel for the first one, we ...
We currently have a customer that wants us to implement push notifications to our app. The problem is that for this customer, security is really, really important... I am not able to find any official documents, that state that the only way to send push a notification to an Android or iOS device via internet is the use...
Let's say we have an application layer with some command handler and we use an Entity Framework database context/ORM context in that handler. I would invert dependencies from the Entity Framework/ORM to the Application layer like this: Create a repository interface with some CRUD functions in the application layer com...
I am writing an app that mainly consists of just creating, editing and reading records in database. I was persuaded that any app has to be covered with tests. I was told that it's a good practice to mock DB out of tests. However in my app if I remove both HTTP and DB then there is almost nothing left. Data validation i...
I was wondering how to updated nested objects/sub-properties when using Entity Framework. But to make things clear, let's start with an example. I have an object, which can own a number of other objects. In other words, an object which contains a list of a different type of objects. This could be a person, who has mult...
I'm actually wondering what are the pros and cons of these two ways to handle client side validations / verifications. Let's imagine an application where there is a contact form that needs these information: An email address (with a specific format) A postal address (with a specific postal code format) I have in mind...
I'm looking for a data structure that supports this use case - there must be one out there! A set of objects of type T can be stored in a Group, parameterised by the type T. A grouping has a GroupIdentity that uniquely identifies the group. Any T can only exist in one Group. A management object, let's call it GroupStor...
I am reviewing a colleague's code and as part of the changes, this person introduced a few new pure data classes like so (C#): public class Result : IResult { public bool Succeeded { get; set; } public string ResponseMessage { get; set; } } And then afterwards defined an interface for the data schema, and used...
I need to model a set of tasks in BPMN v2: 1.0 a report is sent out following which two paths emanate: 2.0.1 report is further formatted, followed by 2.0.2 additional information is added to the report 2.1.1 report is reviewed, followed by 2.1.2 information on the report is acted upon 3.0 further action is taken I a...
I'm building a small personal website. Basically, they are 20 short sound files. Clicking a button will play one of those files randomly. Once played, that file will no longer be played. So in total, the user clicks the button 20 times, each time getting a new random sound. My question is should the frontend (angularj...
I am about to create my own event-driven API in JavaScript. Most JavaScript that currently exists, e.g. in-browser JS for controlling the DOM, lets you register event handlers like this: object.on('eventname', function handler() {}); 'eventname' is basically a magic string, which is generally recommended against (righ...
There are a lot of famous open source tools, for example: gcc, git, mercurial and etc. However, they don't provide a nice API for developer. Someone will say, they are command-line tools instead of library. But in my point of view, there is no conflict between a good interactive tools and a good library. It can definit...
A few times in my career I've found myself writing decoders for responses from IoT products or weird apis that insted of using JSON or XML as a response, they reply with something like HC010410290203123, and they provide certain documentation to explain that... HC 01 04 1029 02 03 123 HC = This segment's name 01 = fiel...
I am currently in the process of developing an ASP.NET Core application which requires internationalization to Russian. I have been reading over the documentation that Microsoft provide for .NET Core internationalization, which requires wrapping your strings in the IHtmlLocalizer and IViewLocalizer interfaces. My bigge...
We are replacing a legacy application that runs on a single Oracle DB, and the decision has been made to replace it with a microservices-based application running on Azure SQL. Do we do data migration from Oracle via the microservices, or do we do direct data migration from Oracle to Azure SQL DBs? Advantage I see with...
I'm trying to build a project using onion architecture (just a "Northwind"ish type app to get more up to speed with .NET Core). I also want to get a better grasp on Onion Architecture principals. I understand it's not a one-size fits all solution, but I want to try to utilize most of the principals in this sample app...
For a few months, there's a heated discussion ongoing in Guava's issues (#3302, #3320) about having introduced several internal dependencies, namely "failureaccess" and "listenablefuture". Some of the introduced dependencies are empty, as evidenced by their version-name: com.google.guava:listenablefuture:jar:9999.0-emp...
In my searching although this question seems to get answered a lot, the answers don't really cover what I want to ask. I'm learning assembly and my question is, in higher level languages e.g C data types are defined as a certain length e.g Char: 1 byte Short: 2 bytes Long: 4 bytes Here's a block of memory, say I defi...
I am building a solution where IoT-devices send in measurement-data to an API that's hosted on AWS. For each measurement-type the user can set a threshold value; that when reached will trigger an alert to be sent out. My design is based on events, so each new measurement that's received in the API generates a work item...
(The code I'd have to post is huge, I'll resume to just function names) I'm currently faced with the following issue on my project: I have a "each module from this framework can have a small view that users use to control its behavior" view-container sort of. Basically each module can have a visual spot in a list, wher...
I need to create a program to manage an association. Members of this association have different roles and each role has specific characteristics. My problem is that I'm not able to abstract this concept in my program. This is what I thought so far. Create a class Person that has generic attributes for members and not m...
The language is PHP. I have the certain, in my opinion, code smell, it doesn't feel right: In my controller class that ingests objects of the same type (interface, it's ViewBlockInterface), I check if these certain objects have certain methods and based on that, do stuff, if not, just skip that object in the array. if(...
How to create a recommendation algorithm ("If you like X and Y, you might like Z")? I want to create an algorithm which recommends "You might also like" items from an itemlist, based on user's current liked itemlist (favorites) and based on those created by other users with similar preferences (in JS/MySQL, but that sh...
We are using GitHub and CircleCI. I know that pull request mergeability can be made to be dependent on the most recent commit, using status checks. Is there any way to make it depend on whether or not a build is running? How?
We have a large Git repo. The files are a mix of styles: tabs vs spaces, unix vs windows line ending, JSON formatting styles, etc. We'd like to change every file to be consistent. However, if I make the change, git blame will show me as the last person to modify every file in the repo. This would be literally true, bu...
I need some advice... I started working at a financial business world recently. Looks like the DB architect uses auto generate function to create stored procs. At the end, we have way too many procs doing almost 100% same thing. Let's say, we have a table with a flag. He creates 3 different procs to pull out the dat...
The SRP seens fairly reasonable when you first look at it. Every class should have one reason to change. Every class should take care of one thing. Right. But let's see this class: Employee { CalculatePay(); Save(); DescribeEmployee(); FindByID(); } This class was used as an example by Robert C. Martin...
One reason I like .NET is because the 'solutions' and 'projects' lends themselves to good architecture. Good architecture makes it easy to follow the happy path of Domain-Driven Design. I've fallen into a habit of this kind of architecture for my projects. It's just a common sense approach for the onion architecture, p...
It is widely accepted, that UT's are necessary for any large project with automated testing. However, it is rarely the case, that 100% of the production code is covered by UT's. There are of course, marginal cases, where UT's are useless waste of resources, e.g. simple setters/getters. On the other hand, there are case...
I have encountered two patterns to make a singleton class Holder class public class Singleton { private static final class Holder { private static final Singleton INSTANCE = new Singleton(); } public static Singleton obtain() { return Holder.INSTANCE; } } Instance variable class public...
This question is about how many bits are required to store a range. Or put another way, for a given number of bits, what is the maximum range that can be stored and how? Imagine we want to store a sub-range within the range 0-255. So for example, 45-74. We can store the example above as two unsigned bytes, but it strik...
Let's say I want to use CosmosDB for Event Store, where have single collection for all events. Currently it is not horizontally partitioned, but it is a possibility for future. Now, I need to implements event handlers, ideally as Azure Functions, but AppService will work well as well. Do you have some guide, how to imp...
So, essentially the flow of my application works like this: A user selects some options to start a process on the server. Once they hit submit, on the server it opens up a console application that processes large amounts of data and then exits when it's finished The idea being that the user can start multiple processe...
I am trying to understand trunk based development with semantic versioning for a Python project. Has anyone had any experience of adopting a trunk based development with semantic versioning for packages? I store the semantic version in version.py:__version__ On the trunk (main) version.py:__version__ would be 1.0.0-SNA...
If I were to have a class with a property on it should I be testing the get and set functionalities separately or together? class MyObject { public string Name { get; set; } } [TestClass] class MyObjectTests { MyObject subject [TestInitialize] public void TestInitialize() { subject = new M...
When learning Git for the first time, I posted Git branching and tagging best practices. I learned a lot from this and have adapted git flow patterns to my personal projects since then. I am now in charge of a project at my job where I am trying to apply these concepts with a team for the first time. We have been mergi...
Can someone explain how floating point numbers are stored in C, as for 32-bit float, 1 bit is parity, 23 bits for mantissa and 8 bits for exponent. So for numbers greater than 2^23(still in the float range), there is no space in the mantissa to store them.
We have a web app in which we allow users to log into the app using any Open ID provider(e.g. Okta, Google, Facebook etc.). We want to implement the correct Open ID Connect prescribed methodology/workflow to keep the user logged into the site. The existing implementation, looks at the expiry of the Access Token then if...
I am interested how multi datacenter (multi homing in Google terms) systems handle writes to strongly consistent user data? Is the master replica for each user placed in the same datacenter and writes are done through log structured queue (or directly forcing the user to wait)? Alternatively, do companies use an archi...
I read through a code example on github and instead of initializing the object using a constructor, they made every setter return the object itself to call it over and over again See, constructors DataSetIterator mnistTrain = new MnistDataSetIterator(batchSize, true, rngSeed); vs chain of setters MultiLayerConfigur...
I'm working on an infrastructure for inter process communication. I have created two interfaces, one to send data and another one to listen to data being sent: public interface ISender<T> : IDisposable { void Send(T dataToSend); void Disconnect(); } public interface IListener<T> : IDisposable { event Even...
I have a project where I develop a software which consists of a CORE which is in a separate project, developed separately, and a CLIENT which's base is the CORE but adds to the functionality with modules and whatnot. But also extends the System and other CORE classes. This is required because there are multiple SUBCLIE...
I am coding a poof-of-concept throw-away GCC plugin (see this for more context) which would use the HTTP 1.1 protocol to interact with my Bismon (GPLv3+ code on github, but unreleased; draft technical report here) system (which provides some Web & HTTP service using libonion). Both server and client are on the same tru...
I have to work on some code that was CAST-audited. The report says that it is bad in Java to use public static and that accessors should be preferred. That is also what I was taught at school. The application uses public static fields in various classes to define the values that should be used in attributes etc. Coming...
Some base points: Python method calls are "expensive" due to its interpreted nature. In theory, if your code is simple enough, breaking down Python code has negative impact besides readability and reuse (which is a big gain for developers, not so much for users). The single responsibility principle (SRP) keeps code re...
I have been practicing this hybrid approach for dependency injection in the last couple of days and I am wondering if it should also apply to components which are within the same package? For example: I have a GPIO module that uses the device chip and that required to be mocked for unit testing. I also exposed its Pin...
I have an application that connects to SQL Server using windows credentials, which works very well for the domain paradigm. The client is now transitioning away from having a domain server, and is going to a distributed model using Sharepoint (the company is perhaps only going to exist for another couple of years). T...
I'm trying to follow the Model–View–ViewModel pattern in a Xamarin application and am wondering how the View should be able to change when a given ViewModel is finished. Below I have listed the ideas I have come up with doing what I need. Creating the new View directly in the ViewModel. Currently, each ViewModel explic...
In Rust, Send (or Sync) marker traits are used to indicate whether a value of a type (or a reference to that) can be worked on within threaded context. However, it is an attribute of a function or a procedure that whether it is thread-safe, as frequently seen in C function man-pages (e.g. man 3 rand). So, why rust is d...
I'm working with some software that uses an HTML form for a user interface to change some configuration information. The back end is a database (loosely speaking). The front end has a hierarchy of values which can be changed in <input> or <select> fields When's the right time to push user-initiated changes into the dat...
I am building a JSON-RPC over UDP socket API in Java. There are 6 objects that will be transmitted in JSON: jsonRequest jsonSuccessResponse jsonError jsonErrorResponse jsonNotification jsonSubscription Under most of these, the following fields would be added to the message and be of types String and Integer: Version...
I'm planning an application in C# which has a feature of sending messages. ATM I'm doing the non-businesslogics and frameworking stuff. The idea was to make an abstract base class which is inherited when used. In there, i'll implement what should happen with the message and when another one should be sent Ex: abstract ...
We have been developing a requirements model for a travel agency system. There are two kinds of member users: premium and free. Both users are able to cancel their previous reservations. Unlike premium users, free users have to pay a cancellation fee as a result of cancellation. In the use case diagram for the previou...
I have read lot of articles on google how kafka cluster works. Trying to summarizing my understanding here . Please let me know if any point is not correct here? Producer Side Say Kafka cluster have one Topic with three partition(P1,P2,P3) on three nodes. Each partition has two replica(R11, R12),(R21, R22),(R31, R32)...
For a long time, the use of these Monad structures has been restricted to a very small circle of languages, many of them purely functional (mainly due to problems related to the management of the IO). Recently, these structures have also been adapted to imperative languages My question is: we talk about same design pat...
We have a system that holds credit balances, and we thought event sourcing would be a good fit. Getting the current balance by reading from an eventually consistent projection works. However, I still don't understand how to make sure that the debits/credits on the credit balance is valid/consistent without going throug...
In the context of SDLC, I know that Verification and Validation is about verifying the deliverable input from previous phase and validating the output of the current one. And that testing is a phase among the SDLC phases. Based on my research, I found from UToronto lecture notes that: V&V performed by a separate contr...
Suppose I have game achievement class that stores achievement information like name, popup message, etc. class GoldMedal implements GameAchievement { @Override String getName() { ... } @Override String getAchievementDisplayMessage() { ... } } Then when the game ends, I want to record current achievements to...
What are best practices for modeling "arithmetic business types" like money or time? Is it recommended to make classes with explicit plus/multiply operations? Should there be a class for every currency? Or is it more practical to not model them at all with the type system and keep them as BigDecimal? Example: The bu...
We have a product that contains features (Let's say feature A, B and C). We are about to move it to production (a web application) for a certain client. However, as per my boss, we will deploy the product to the client's premises. The client will also have the source code. Now, my boss wants to restrict the features fo...
I am practicing professional C++ by building a differential drive robot that applies a Go-To-Goal Behavior. What is I have written so far is an Agent that consumes the following interfaces: Actuators Interface Odometry Interface PID Regulator Interface The motion of a differential drive robot is governed by the unicy...
I don't dislike global state, but that could be due to the lack of experience. I was thinking about what the usual implementation of global state is: A big variable where data flows in a non-consistent, unpredictable but most importantly, non-standardized way, referring to all CRUD operations. An implementation like gl...
Problem Say we have a C# class with is serialized to JSON (currently via Newtonsoft's JSON.Net) and stored in a database: public class User { public string authInfo; } If the class definition changes, the old data will fail to load. Even if we try to update the database by hand, data may be lost unless we have ser...
We have a web application that all update, insert and DB operation procedure handle via SQL Server DB 2017. What is the best way to handle and get error (in Web-app or SQL server error handler?). for example a foreign key error occurred, is it better to handle it via DB or Code? Update 1: for all operation from serve...
I am developing a website where customers can register products they bought in order to receive a benefit in the form of e.g. a cashback, a discount or promotional goods. In the future, we also plan on developing more of these websites in the future. The website includes the following several registration steps: One o...
My team is interested to apply TDD in our next software project. We have a discussion about how many details should be specified in design specs before the developers start coding. Some of us propose that we should specify all classes and their relationship in specs before writing code because we have to design all tes...
I am building my first web application, it links to the serverside through RESTfull Web API (Angular on client side, ASP.Net Core and EF Core on serverside, Automapper to map API Resources to/from domain models). In the application I have two main models (simplified below as Delivery and Order) and each has its own API...
I am planning a spring boot application that can be extended with plugins. However, I haven't found out yet whether spring boot meets my requirements in this regard. I imagine the following folder structure: application core <-- core jars main_application.jar ... plugins PluginTypA...
I'm using a pretty old library to make server requests which is not properly tested and it not really matching nowadays requirements, so the plan is to migrate to a new one over the next release. So the idea is to plan a migration testing suite in order to make the transition painless. The thing is, the new library wor...
I'm trying to switch to clean architecture from a traditional layered architecture approach and trying to figure out where to put business logic. Please consider the below scenario - Employee class (exists in Efcore db first scaffolded in core)- class Employee { public int Id {get; set;} public int TimeWorked {...
I am trying to create a Put endpoint using rest. Let's say that under the link /addresses/12345 I am trying to add a new address (if that id doesn't exist) or I'm trying to update it if it does already exist. My application has several layers Controllers, Services, Models and Repositories. Given the fact that the busi...
I need to send jobs to worker queues according to resource usage and other metrics like how many jobs have been processed and how successful they were. There is also the need to “weight” these parameters to each other eg that if the success rate drops under an acceptable value others values might me acceptable now? Ho...
My intuition tells me that moving duplicate/common codes among subclasses to the superclass (so superclass now have a new method) is a bad idea, but I have seen this technique used/described in both Design Pattern and Refactoring(e.g. pull up method) books. After some thinking my idea is that now subclasses' behavior i...
On our prod db we have two tables: companies invoices Relationship: A company has many invoices An invoice belong to a company The invoices table contains duplicate invoice_number for each company. What is the best approach to make invoice number unique for each company. what ever approach we go with, the changes sh...
Recently, I've became the integration lead for a large distributed system. I have two main challenges before I can take on anything else: first document all system interfaces and it's relationships and prepare to upgrade for a new cloud infrastructure (and getting away from IBM stuff). The first goal is tricky. We got...
We are building an pseudo-rest API (because no body cares/funds for a full blown rest API for internal use - which is OK). So we have elements of Rest API (links for resources, API naming conventions and standardized output data model following some naming conventions in google json standards). But because of this Our ...
I just have an idea about dependency management in Spring IOC environment that seems to be better than the typical approach, but I am not sure because I can't find any references or example out there that talk about it, though the idea is very simple. I will explain the idea comparing to the typical approach. Please he...
I have multiple REST-ful APIs that I'm using as my "back-end". I also have multiple web apps (.NET MVC). These web apps make calls to the APIs for data. So, an object being returned by an API will be the same as the object being expected on the web app side (serialized from JSON of course). For example, if my web app m...
I have a Parent object which looks like this (pseudocode): class Parent { String token; Child[] children; } It contains a token string and an array of Child objects. My problem is that each of these Child objects needs to access the token string from the Parent class. My first hunch is to loop through the children...
I am looking to build an app where the only way a new user can enter the app is if they have been invited by an existing user. Are there any API's, tutorials or resources that can help me achieve this. I am using Firebase as my backend and I know it has phone number verification, but I want only invited users to be giv...