logger initialization in JEE based web application

While working on a web (JEE based) application I saw some different ways people have instantiated loggers in different classes. First way is classic way like,

private static final Logger logger = LoggerFactory.getLogger(AbstractPersistenceObjectDAO.class); 

but as JEE applications are CDI enabled in some managed classes it was injected like

@Inject private Logger logger; 

is there any advantage if using logger with CDI, in terms of performance (time or memory)? Are there any downsides of any of these approaches? While @inject can only be used in managed environments, does it offer any advantage over other?

Clean architecture – How do I deal with use case reuse?

Trying to apply Uncle Bob’s clean architecture to an application I’m maintaining and I’m having difficulties with use cases and duplication/reuse. It’s my understanding that usecases should be self contained and that duplication is to be expected but this does not seem to make sense with what I’m dealing with. I feel there are multiple use cases that should end up using other use cases.

Here is a very simplified example of 4 use cases that exist separately but that are also dependent on each other in the following way.

BulkSendUsersToUnit                    SendUserToUnit            AddUserToMandatoryGroups               AddUserToGroup  

Each of them have validation, repository calls and conditions that always apply. Basically if I was doing this with services they would simply be methods that I would call from where I need them.

Can I/should I inject use cases in other use cases using DI?

What am I missing here?

Design question on synchronization of two asynchronous data streams

I have two async streams suppose- Trip : {tripId, date, city} Bill : {billId, tripId, date, amount}. I need to design a system to get real time aggregated view of following nature: City, TripCount, TotalAmount. Events in both streams can be out of sync or duplicate. But result needs to be accurate and realtime.

My Solution:

1.) Create two different DB tables: Trip and Bill (indexed on TripID and BillID). Read the messages from the streams and persist in these tables with the status column as pending in Bill table and Trip table. Then write a worker which will read from the bill table and look into the Trip table for the record containing the given tripID. If the record is found it will update the aggregated view in third table (City, TripCount, TotalAmount). Then we will change the state of the bill and trip record to processed. There will be one background job running on periodic basis which will remove all the records which will have the state as processed from both Bill and Trip table.

The problem i see with the above solution is the indexing that done on the TripID and BillID will become a bottle neck if i remove the records at very high frequency. Other from it do you guy see any other problem with this solution. I have read on internet that people are suggesting it as very famous anti-pattern cause here i am using DB as queue.

2.) Here is other solution: Take the data from the streams, persist it in the tables: Trip, Bill (for audit purpose of records and to avoid duplicates). For storing the Trip data temporarily take one distributed key-value pair very fast data structure. I am taking REDIS for this purpose. So, after writing trip data to DB, i will write the same data in the cache with tripid as key and record as value. Then i will put the bill data in the queue. Workers will be reading from the queue and will lookup into the cache for the tripid. If the tripid is present then the workers will read the data from cache and update the aggregated view and delete the tripid from the cache and also bill message from the queue. If the tripid is not found in the cache then then worker will again put the same message in the queue back.

To avoid duplicates, the insertion will fail if we will try to insert same tripid or billid in the tables. In case where the insertion will fail, i will not put the message in the queue and cache.

Experts please let me know about your thoughts on the above two solutions and please propose any better solution if you have any.

Designing survey software [on hold]

I am looking to design a piece of survey software in C# that asks questions and based on the response would determine which question is asked next.

The questions would have a selection of 2 or more options. Based on the option selected would determine the path to the next question

So for example assume questions are numbered 1 -> 5, each would have 2 or more options (a,b,c). Depending on the option selected next numerical question could be skipped, so if option (a) was selected for each question the questions might flow numerically, if (b) selected the numerically the following question could be skipped. For example where the number is the question and the letter the selected answer:

1(a), 2(a), 3(b), 5(a),6(c),8(b) and so on

I wondered if there is an applicable design pattern/sensible data structure that would show me a good place to start. I don’t know how to design a data structure that would enable me to link questions in this manner

I am hoping to avoid writing something procedural with extensive conditional statements, I have no fixed requirements regarding how the answers/questions/content should be stored so any advice around whether relational or document based would be much appreciated.

OAuth2 – Application user registration and data decoupling

I’m designing a microservice architecture consisting of a central authorization service (OAuth2) and a resource service (REST API + Database). The resource service handles confidential user information as well as front-end content (CMS).

After looking into OAuth2, I figured the best way to design this in a secure way is to use two grant types:

  • Password Grant for user authentication and to let the first-party mobile application obtain an access token for the user and use that to access the user’s confidential information on the resource server.

  • Client Credentials for authorization of the client (mobile application) when accessing the resource server and fetching the front-end content.

The part where I’m currently stuck is how to design an user registration flow. I only want to store the minimal required user data for authentication on the authorization service (username/email and password) and store any other (confidential) user information on the resource service (name, birthday etc.).

Would it be a good design to let the authentication server notify the resource server upon registration or do I need something like a message queue? Also how would it be possible to keep the shared user information (uid, username or email) in sync between the authorization service and the resource service?

Why do software engineers refer to computers as “machines”

Since entering software engineering, I picked up the habit of saying “machine” when talking about a computer. Most of my colleagues seem to do the same. However, when I use this idiom in everyday conversation, people get a bit confused.

Obviously, a computer is a machine. However, most machines are not computers. So it’s a bit non-obvious why we do that.

So what is the history behind this practice? Where does this come from?

What are some efficient and easy-to-remember schemes for randomly-generated sequential ID numbers?

I am considering a new scheme for order numbers for our ERP system. For reasons I’d like not to get into, the number must be fairly easy to remember and must say something about the time (or at least sequential order) the order was placed. This eliminates things like UUIDs as an option, since those are both very hard to remember and lack any time information.

Another constraint is that I’d like the scheme to be able to handle multiple users generating numbers without any collisions. This can be done with something like a ticket server (which is plan B if this fails). This is where UUIDs would be perfect, if they met the other criteria.

I’m looking for a balance between minimizing the likelihood of collisions and the ease of remembering the number. This sounds impossible, but our business is small and these collisions would be very unlikely to happen even if the ID were a simple timestamp.

One idea was to essentially generate a number that represented a timestamp down to the current second, and append another few random digits to significantly decrease the chances of a collision. The more digits I add, the lower the probability of a collision, but the angrier my coworkers would be at me.

Is this even in the ballpark of sane? This seems like a problem others have run into and I’m curious to know how they solved it.

Best practices for usage of 3rd-party API with another API?

I’m building a tool for my school that will interface with the Canvas API, and as of now the repo is structured as an MVC app with the main folders being models/, controllers/, and routes/. What are some best practices with regards to directory structure when integrating other APIs into your own? Is adding a services/canvas.rb the right idea?